这个程序有什么问题。什么导致无限循环。 C

时间:2015-05-01 07:22:12

标签: c

该函数应该从文件中读取每一行并将每一行发送到另一个函数。但是在代码的注释部分出现错误。那是为什么?

我将每个字符存储在一个字符数组中。它应该很简单。我不明白为什么它不起作用。是因为它的数组没有将它存储在其中吗?

我想我添加了关于该程序的足够详细信息,但我得到了红色的说法,我需要添加更多。希望这已经足够了。

void exercise3(void)
{
    FILE *  inputFile;
    char    line[64];        
    int number_of_conversions=1;
    int i = 0;        
    printf("BEGIN EXERCISE 3\n");

    // Open the file /public/lab10ex3.txt for reading. Store the handle in the
    // variable inputFile.
    // (WRITE THE CODE HERE)

    inputFile=fopen("/public/lab10ex3.txt","r");

    // Test to ensure the file was successfully opened. If opening the file
    // failed, display an error message, and exit the program with an exit
    // code of 1.
    // (WRITE THE CODE HERE)

    if (inputFile==NULL){            
        printf("bad stuff \n");
        exit(1);
    }

    // Read each line from the file into the character array 'line'. Pass
    // each line of text to the processDrawCommand function.
    // (WRITE THE CODE HERE)

    while (number_of_conversions!=0 && number_of_conversions!=EOF ){                                       
        number_of_conversions=fscanf(inputFile,"%c",&line[i]);    //Error Here

          if (line[i]=='\n'){
              i=0;                  
              processDrawCommand('\n');
          }              
          processDrawCommand(line);
        i++;                                                            
    }

0 个答案:

没有答案