reading input from text file into array of structures in c

前端 未结 1 490
伪装坚强ぢ
伪装坚强ぢ 2021-01-13 21:48

My structure definition is,

typedef struct {
    int taxid;
    int geneid;
    char goid[20];
    char evidence[4];
    char qualifier[20];
    char goterm[         


        
相关标签:
1条回答
  • 2021-01-13 22:12
    char mystring[100];
    FILE *p = fopen ("gene2go.txt" , "r");
    if (p == NULL) perror ("Error opening file");
       else {
         if ( fgets (mystring , 100 , pFile) != NULL )
           puts (mystring);
          pch = strtok (mystring, "\t");
          while (pch != NULL)
          {
              //handle each token here and insert into struct
              pch = strtok (NULL, "\t");
          }
         fclose (pFile);
       }
       return 0;
    

    Refer to strtok, fgets

    0 讨论(0)
提交回复
热议问题