For ad please specify what will be the return value of the f

For (a)~(d) please specify what will be the return value of the function f scan f and the value of the variable data1 (and data 2) after we call the fscanf function? Don\'t be confused with those values they\'re different For each question, let\'s assume that a text file is just opened successfully. The box represents the text file and its content Suggestion: Write a short program to test your answers. FILE *fp = fopen(\"myfile.txt\".r\");int data1.data2; fscanf(fp, %d\", &data1;); fscanf(fp. \'%d%d\". &data1;, &data2;); fscanf(fp, \"%d\", &data1;); fscanf(fp, \"%d\" &data1;);

Solution

a)

1) Return value of fscanf method is 1 . Because this function fscanf returns number of items matched and assigned successfully which is 1 in this case.

2) Value in the data1 variable is -123 which is the first value in the file

b)

1) Return value of fscanf method in this case is 2. As we explained before , as we have to items matched to the input , it is 2.

2) Value in the data1 variable is -123 and data2 variable is 23

c)

1)Return value of fscanf method in this case is 2

2)Value in the data1 variable is -123 and data2 variable is23.

c 2nd part)

1) Return value is 0

2) data1 value will be maximum integer value

d)

1)Return value of the method fscanf in this case is -1.

2) data1 value will be maximum integer value

 For (a)~(d) please specify what will be the return value of the function f scan f and the value of the variable data1 (and data 2) after we call the fscanf fun

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site