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
Special characters of comma (,) quotation mark, and new line character may cause issues with a CSV import. If you get an import error, open the CSV file in Excel and use the Find & Replace tool to change or remove these specific special characters.
CSV (comma delimited) will not open correctly and the data within will be displayed incorrectly. This is due to regional Excel settings that have default list separator options where files will either be read with a comma separator or semicolon separator.
Some people's name use commas, for example Joe Blow, CFA. This comma breaks the CSV format, since it's interpreted as a new column. I've read up and the most common prescription seems to be replacing that character, or replacing the delimiter, with a new value (e.g. this|that|the, other ).
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With