Hi there,
Please bear with me. I have a file with multiple columns. I would like split and perform some operations.
When I read file and split using strtok on tab separate it works fine, but I get first split from previous line in print.
I have input file asCode:int main(int argc, char *argv[]) { // gcc -Wpedantic -Wextra -Wall *.c -o parse FILE *fp = fopen("test_cuts.txt", "r"); if (fp == NULL) exit(EXIT_FAILURE); char *line = NULL; size_t len = 0; while ((getline(&line, &len, fp)) != -1) { char *token = NULL; token = strtok(line, "\t"); int count_split = 1; while (token != NULL && ++count_split <= 8) { printf("split %s\n", token); //printing each token token = strtok(NULL, "\t"); } // using printf() in all tests for consistency printf("%s", line); } fclose(fp); if (line) free(line); return 0; }
When I run code, I get unwanted stored :
Chr Start End Ref Alt Func.refGene Gene.refGene GeneDetail.refGene ExonicFunc.refGene AAChange.refGene
21 10000766 10000766 T C intergenic LINC01667,BAGE dist=179705;dist=412754 . .
21 10001677 10001677 G T intergenic LINC01667,BAGE dist=180616;dist=411843 . .
21 10002110 10002110 G A intergenic LINC01667,BAGE dist=181049;dist=411410 . .
21 10003899 10003899 T C intergenic LINC01667,BAGE dist=182838;dist=409621 . .
21 10005858 10005858 T C intergenic LINC01667,BAGE dist=184797;dist=407662 . .
21 10005978 10005978 G T intergenic LINC01667,BAGE dist=184917;dist=407542 . .
21 10006274 10006274 G T intergenic LINC01667,BAGE dist=185213;dist=407246 . .
21 10010233 10010233 T C intergenic LINC01667,BAGE dist=189172;dist=403287 . .
21 10014276 10014276 T C intergenic LINC01667,BAGE dist=193215;dist=399244 . .
I do not want
split Chr
split Start
split End
split Ref
split Alt
split Func.refGene
split Gene.refGene
Chrsplit 21
split 10000766
split 10000766
split T
split C
split intergenic
split LINC01667,BAGE
21split 21
split 10001677
split 10001677
split G
split T
split intergenic
split LINC01667,BAGE
21split 21
Chrsplit 2121split 21
rather, split 21 only.
Where is this basic code going wrong?