Hi everyone,
I have decided to take a intermediate level C programming course with absolutely no programming experience. Most of the HW involved manipulating integers but the last question involves strings and I don't know how to manipulate them and I am running out of time.
I have to create a program that features a loop that prompts the user to enter a string of lower case letters and tallies the frequency of each character. The code I have does that, but I can't figure out how to phrase the loop condition to that will prompt the user again for a string and then add those character tallies to the total. The program is supposed to keep prompting and adding until an EOF character (CTRL+Z or ^Z) is entered.
All my attempts either go into an infinite loop without printing or overwrites previous counts a new tally for every subsequent string.
HELP!
Code:
#include<stdio.h>
#include<string.h>
main()
{
char string[100], ch;
int c = 0, count[26] = {0};
printf("Enter a string");
scanf("%c", &string);
while ( string[c] != ''\0' )
{
if ( string[c] >= 'a' && string[c] <= 'z' )
count[string[c]-'a']++;
c++;
}
for ( c = 0 ; c < 26 ; c++ )
{
if( count[c] != 0 )
printf("%c occurs %d times in the entered string.", c+'a', count[c]);
}
return 0;
}