linux - CSV FILE generator in C -


is there c program can run on linux box, , create csv file of given dimensions(rows x columns) , store on hard disk?

a csv file plain text file comma separated values , can therefore create hand in plain text editor. there specification in rfc 4180.

often first row used column names such as:

 name, account no, amount niels, 1234, $0.99 thomas, 8888, $10.00 per, 3454, $9.00 rasmus, 9412, $99.99 

a small c program create plain , empty csv file like:

/*  * makecsv.c   */  #include <stdio.h>  int main(int argc, char **argv) {    if( argc != 3) {       printf("mandatory arguments: <rows> <cols>\n");          return 1;       }        int row, col;       for(row = 0; row < atoi(argv[1]); row++) {          for(col = 0; col < atoi(argv[2]); col++) {             if(col > 0) {                printf(", ");             }             /* default values "row x col" */             printf("\"%dx%d\"", row, col);          }          printf("\r\n");        }        return 0; } 

i'd compile , run following commands:

 $ gcc -o makecvs makecsv.c  $ ./makecvs 3 4 "0x0", "0x1", "0x2", "0x3" "1x0", "1x1", "1x2", "1x3" "2x0", "2x1", "2x2", "2x3"  $ 

to place output in file "the unix way", pipe output file using following commands:

 $ ./makecvs 3 4 > myfile.csv 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -