Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Intro to C programming question: Write in the text box window below a function c

ID: 3775158 • Letter: I

Question

Intro to C programming question:

Write in the text box window below a function countInFile that takes as parameters a file name fname (of type char[]) and a character c and that returns the number of times character c occurs in the file. You need to open the file, then read characters (one by one) in a loop and count, and, finally, close it before returning the count.

The function prototype is:

int countInFile(char fname[], char c);

For example if a file named “text” has the content “all men are created equal”, then calling

countInFile(“text”, ‘e’)

should return 5.

Ensure the code is correct, aligned, and indented properly. Use meaningful variable names.

Explanation / Answer

#include #include void find_frequency(char [], int []); int main() { char string[100]; int c, count[26] = {0}; printf("Input a string "); gets(string); find_frequency(string, count); printf("Character Count "); for (c = 0 ; c < 26 ; c++) printf("%c %d ", c + 'a', count[c]); return 0; } void find_frequency(char s[], int count[]) { int c = 0; while (s[c] != '') { if (s[c] >= 'a' && s[c]
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote