Quote:
How to find frequency of characters in each line of a passage in C?
All what you do to get the result for a single input, you will have to do for each input line.
You need to find how to input many times, with how to know that input is finished. With every input line , apply same procedure to get frequency on the line.
Nota: you may want to skip letters seen zero times, and you may want to have more than a single letter per result line.
Advice: learn to search C++ reference
gets - C++ Reference[
^]
Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
#include <stdio.h>
#include <string.h>
int main()
{
int i;
char str[1000];
int arr[26] = { 0 };
gets(str);
for (i = 0; i < strlen(str); i++)
{
if (str[i] >= 'a' && str[i] <= 'z')
{
int temp = str[i] - 'a';
arr[temp]++;
}
else if (str[i] >= 'A' && str[i] <= 'Z')
{
int temp = str[i] - 'A';
arr[temp]++;
}
else
continue;
}
for (i = 0; i < 26; i++)
{
printf("%c=%d\n", i + 'a', arr[i]);
}
}
Indentation style - Wikipedia[
^]
Best C++ Formatter and Beautifier[
^]
Online C/C++ Formatter, Indenter and Beautifier – Techie Delight[
^]
Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[
^]
ultraedit[
^]
Enabling Open Innovation & Collaboration | The Eclipse Foundation[
^]