you need to write a C function named counte. The prototype is: int counte(char*)
ID: 3594686 • Letter: Y
Question
you need to write a C function named counte. The prototype is:
int counte(char*);
The function accepts a string and counts the number of times a
lowercase e ('e') occurs in the string.
counte returns that count as its return value.
Put your counte function in a file named counmte.c
If you use strlen, you'll want to include <string.h> in counte.c
Write your own main test function to test your counte function.
If your main function is called main.c compile as follows:
gcc -o main main.c counte.c
Explanation / Answer
#include <stdio.h>
#include <string.h>
int counte(char *ch) {
int size = strlen(ch);
int i, count = 0;
for(i=0;i<size;i++){
if(ch[i] == 'e') {
count++;
}
}
return count;
}
int main()
{
char s[100];
printf("Enter the string: ");
scanf("%s", &s);
printf("Number of 'e's: %d ", counte(s));
return 0;
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.