IHYPRESS PROGRAMMING
Tutorials and C programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
CStrings : CSV File Processing
<08.09>
/* processing a CSV data file */ #include <string.h> #include <stdlib.h> int main (void) { FILE* datafile; //file variable char* token; //the token string char line[1000]; //the line read from the file char del[]=","; //the delimiter (a string). "," for CSV datafile = fopen ("data.txt", "r"); //open file while (!feof(datafile)) { //the first token fgets (line, 1000, datafile); token = strtok (line, del); //the other tokens (0 token means the end of the line) while (token != 0) { printf ("%s\n", token); token = strtok (0, del); } } fclose (datafile); }
Hergestellt in Deutschland / Made in Germany
Berlin 77 22.3 44.2 25.6 Hamburg 23 25.6 11.2 15.77 Munich 66 6.6 7.7 2.2
data.txt file contains:
Berlin,77,22.3,44.2,25.6
Hamburg,23,25.6,11.2,15.77
Munich,66,6.6,7.7,2.2
COPYRIGHT © 2015-2025 IHY PRESS Frankfurt am Main 60329 Deutschland