Menu

Please Find The Error In The Following C Language Code When The Output Is The Same As The Input Of The Trace File. There Is A Trace File With The Following Data. 75400fe8 N 75401028 T 75401024 N 75401028 T 75401024 N 75401028 N 75401034 T 754011ec T 75401208 T 754013b0 N 75401024 N Code: Char Array[100]; Scanf(“%S”, Array); FILE *TraceFile = Fopen(Array,

Please Find The Error In The Following C Language Code When The Output Is The Same As The Input Of The Trace File. There Is A Trace File With The Following Data. 75400fe8 N 75401028 T 75401024 N 75401028 T 75401024 N 75401028 N 75401034 T 754011ec T 75401208 T 754013b0 N 75401024 N Code: Char Array[100]; Scanf(“%S”, Array); FILE *TraceFile = Fopen(Array,

Please find the error in the following c language code when the output is the same as the input of the trace file.

there is a trace file with the following data.

75400fe8 n
75401028 t
75401024 n
75401028 t
75401024 n
75401028 n
75401034 t
754011ec t
75401208 t
754013b0 n
75401024 n

Code:

char array[100];
scanf(“%s”, array);
FILE *traceFile = fopen(array, “r”);
if (traceFile == NULL) {
fprintf(stderr, “Cannot open file\n”);
return 1;
}
unsigned int pcIndex;
char tnt;
int i = 0, j, total = 0, takenornottaken = 1;

while(fscanf(traceFile, “%u”, &pcIndex) != EOF){
fscanf(traceFile, “%c”, &tnt);
if (tnt == ‘t’) {
takenornottaken = 1;
}
else if (tnt == ‘n’) {
takenornottaken = 0;
}
//j = makePrediction(pcIndex, rb, gpb);
if(takenornottaken == 1 && j == 1){
i++;
}
else if(takenornottaken == 0 && j == 0){
i++;
}
total++;
//updatePredictor(pcIndex, rb, gpb, takenornottaken);
printf(“%u %c\n”, pcIndex, tnt);
}
//float MissRatio = (i/total);
//printf(“%d %d %.2f\n”, gpb, rb, MissRatio);
fclose(traceFile);

Expert Answer

Step 1

The provided code appears to have some issues:

OR