You take a string and count the number of e.
Enter the string as scanf and save it to the array.
#define LEN 100
char line[LEN];
printf("Enter a string:");
scanf("%s", line);
If you have e, you can iterate the input array and count to +1.
short cnt = 0;
for(char i = 0; i < LEN; i++){
char c = line[i];
if(c == 'e') cnt++;
}
If the count is greater than or equal to 1, output the count, and if it is 0, output bye.
if(cnt > 0) printf("%d.", cnt);
else printf("bye.");
It seems like homework, so I'm trying to ignore it, but I only add the key parts.
© 2024 OneMinuteCode. All rights reserved.