Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //get the count of the columns per line
- int *get_column_map(char *fn){
- int l=lines(fn);
- int *column_map=malloc(sizeof(int)*l);
- FILE *file_c=fopen(fn, "r");
- int character=0;
- int cc=1, lc=0;
- while(character!=EOF){
- character=getc(file_c);
- if(character==','){
- cc++;
- }else{
- if(character=='\n'){
- column_map[lc]=cc;
- printf("%d\n", cc);
- cc=1;
- lc++;
- }
- }
- }
- fclose(file_c);
- return column_map;
- }
- //get the length of the first column of the csv file
- int getfirstcolumn(char *filename){
- FILE *firstcolumnopen=fopen(filename, "r");
- int x_=0;
- int pos=0;
- while(x_!=EOF){
- x_=getc(firstcolumnopen);
- if(x_==','){
- pos=ftell(firstcolumnopen);
- fclose(firstcolumnopen);
- return pos;
- }else{
- }
- }
- return 0;
- }
- //counts the lines of the file
- int lines(char *file_){
- FILE * file;
- file = fopen(file_, "r");
- int c=0;
- int counter=0;
- int len=0;
- while(c!=EOF){
- c=getc(file);
- if(c=='\n'){
- counter++;
- }
- len++;
- }
- fclose(file);
- return counter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement