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

Problem 5 (8 points): complete the code Complete the C code snippet below to ope

ID: 3753396 • Letter: P

Question

Problem 5 (8 points): complete the code Complete the C code snippet below to open a file passed to a program as «argc-1> from the command line for reading, program character in the file and adds up the total number of cargc-2> characters read to count. Read characters until the Eor is reached. Fill in the code where blank so the code executes and works correctly. Example: ./a.out ThisSourceCode.c a >> returns: Num of e's: tincludecstdio.h> tinclude int main int argc, char arg) itt fprintf (stderr, "zong nunber of arguments td in", arge) return EXIT FAILORE: 1 FILL IN HERE 1 FILE *in- Eopen t Lf (in NULL) tprintf(atderr, "Could not open fileln") return EXITFALURE; - /* read character, add one to count if matches the letter g int count 0 char c. c2: e2argv [21 101a /e complete code below here FILL IN HERE 1 //// TLLIN HERE //// while / end code/ printt "Num of sc's: dn",c2, count) return ExXIT SUCCESS

Explanation / Answer

argc and argv are basic member variables passed in main function

where argc contains the 'number of arguments' can be passed-on

and argv contains the 'vector of arguments'

As per Question there are two arguments

argc (1) holds File Name (which is default)

argc(2) holds the character count

First Fill Statement could be

if (argc != 2) //If argument count is not 2 then throw error and return Failure

{

}

Second Fill Statement Could be

FILE *in=fopen("ThisSourceCode.c","r"); //Open ThisSourceCode.c in read mode

Third Fill Statement Could be

while (1){

c = fgetc(in);

if (c == '@')

{

count++;

}

if ( feof(in) )

{

break; //If you read until end of file , break from the while loop

}

}

fclose(in)

/* end code */

printf("Num of %c's: %d ", c2, count);

return EXIT_SUCCESS;

}

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