I need some assistance. I'm trying to write my code's output into a file. However, I'm encountering an issue whenever I attempt to use fprintf within an array. The code works as it should without the fprintf statements, printing 5 scores per line. When added, it appears to continue increment the array?
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <stdlib.h>
void displayScore(int testScores[]);
FILE *fpOut;
int main(void) {
if (!(fpOut = fopen("csis.txt", "w"))) {
printf("csis.txt could not be opened for input.");
exit(1);
}
int testScores[] = { 90, 85, 100, 50, 50, 85, 60, 70, 55, 55, 80, 95, 70, 60, 95, 80, 100, 75, 70, 95, 90, 90, 70, 95, 50, 65, 85, 95, 100, 65 };
displayScore(testScores);
fclose(fpOut);
system("pause");
return 0;
}
void displayScore(int testScores[]) {
int i = 0;
/*Prints 5 scores every line*/
for (i = 0; i < 30; i++) {
printf("%d, ", testScores[i]);
fprintf(fpOut, "%d, ", testScores[i]);
printf("%5d, ", testScores[i += 1]);
fprintf(fpOut, "%5d, ", testScores[i += 1]);
printf("%5d, ", testScores[i += 1]);
fprintf(fpOut, "%5d, ", testScores[i += 1]);
printf("%5d, ", testScores[i += 1]);
fprintf(fpOut, "%5d, ", testScores[i += 1]);
printf("%5d, \n", testScores[i += 1]);
fprintf(fpOut, "%5d, \n", testScores[i += 1]);
}
return;
}