James Mark James Mark - 4 months ago 26
C Question

Writing to a CSV file in C

My C program generates this data. I need to place it into a CSV file, so that it can be used by another program. How can I achieve this?

Student1 Mark1 Mark2 Mark3 Mark4 Mark5
Student2 Mark1 Mark2 Mark3 Mark4 Mark5
Student3 Mark1 Mark2 Mark3 Mark4 Mark5
Student4 Mark1 Mark2 Mark3 Mark4 Mark5
Student5 Mark1 Mark2 Mark3 Mark4 Mark5

Answer Source

You could achieve this through fprintf

for(i = 0; i < num_of_students; i++)
     fprintf(fptr, "%s,%d,%d,%d,%d,%d\n", name, mark1, mark2, mark3, mark4, mark5);