In this C program i have an array with duplicate student IDs. When I try to write it to a text file, it skips the duplicate values and write the remaining data into the file with value 0 in each duplicated value. But I want to write that duplicate record also into the file.
Here's my code;
int WriteData(struct Sales StoreSales[])
{
int i;
FILE *fptr;
fptr = fopen("reverseOrder.txt", "w");
if(fptr == NULL)
{
printf("\nError: File cannot be opened\n");
return -1;
}
fprintf(fptr, "\nStudent ID\tSales Amount\n");
for(i = SIZE ; i > 0 ; i--)
{
fprintf(fptr, "%d\t\t\t%d\n", StoreSales[i].StudentID,
StoreSales[i].amount );
}
fclose(fptr);
}
Here's my array;
301 -> 4
201 -> 3
657 -> 4
234 -> 9
301 -> 8
201 -> 4
As I'm a beginner to C, I can't find out a way to solve this issue. Any helpful ideas to fix my code? Thank You!