无法解析文本文件

时间:2013-11-22 23:14:38

标签: c parsing

我目前正在尝试挑选文本文件的特定部分,特别是包含不需要的文本的课程目录中的类。我需要获得课程编号,描述,学分和教授。第一次在这里发帖,对于任何格式问题都很抱歉:

void readFile(FILE* input, data** head){
 char* line = (char*)(malloc(sizeof(char) * MAX_LINE));
 int x, y, k;
 y = k = 0;
 data* temp1 = (data*)(malloc(sizeof(data)));
 temp1->next = NULL;
 //get line

 while(fgets(line, MAX_LINE, input)){
  line[strlen(line) - 1] = '\0';
  char* token = strtok(line, "\t");

  while(token != NULL){
   //determine if token is a number, descriptor, etc.
   x = dataT(token, k); //function return int value 1-4 depending on data type found, 0 for garbage

   if(x == 1){
    k = 1; //used to signal if coming after a course number for other data types
    strcpy(temp1->cnum, token);
    y++;
   }

   //etc for rest of types...
   //....
   //load found tokens once four have been found(file will always have one of each before repeating a type)

   if(y == 4){
    loadList(*head, (temp1->cnum), (temp1->cdesc), (temp1->hours), (temp1->cprof));
    y = 0;
    k = 0;
   }
   token = strtok(NULL, "\t");
  }
 }

最后,来自文件的一些输入示例(我需要标记的部分,实际文件中没有星号):

**COSC-010**  **INTRO TO COMPUTER SCIENCE**          **3**
  available seating
  01  LEC T 1:15-2:30 REI 112          **Miles A**
      LAB M 4:15-5:30 STM 343
     CROSS LIST: COSC-501-01
      MSB STUDENTS ONLY
     SPRING ONLY COURSE

我会根据要求提供更多信息。

0 个答案:

没有答案