Segmentation Fault in C when trying to parse on "\t":

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • John Knepper
    New Member
    • Jan 2011
    • 2

    #1

    Segmentation Fault in C when trying to parse on "\t":

    //I apprecaite any help~!

    #include <stdio.h>
    #include <stdlib.h>
    int main(int argc, char *argv[])
    {

    FILE *g_cov, *cov_only;
    char line[50];

    if(argc !=2 ){//argc already has value of one. therefore, must be 2 for one argument.
    fprintf(stderr, "No arguments passed to grab_cov.c");
    return EXIT_FAILURE;
    }

    g_cov= fopen(argv[1], "r");

    cov_only=fopen( "cov.only.o ut", "w");

    if(g_cov==NULL) {
    printf("can't open argv[1] for reading");
    return 1;
    }
    while(fgets(lin e, sizeof line, g_cov)!=NULL)
    {
    char* token=strtok(li ne, "\t");
    while(token!=NU LL){
    printf("[%s]\n", token);
    token=strtok(NU LL, "\t");
    }
    }

    fclose(g_cov);

    fclose(cov_only );
    return 0;
    }
  • John Knepper
    New Member
    • Jan 2011
    • 2

    #2
    I figured it out. nevermind! had to includ string.h

    Comment

    Working...