陷入从stdin(C)读取的无限循环

时间:2015-03-06 03:05:15

标签: c loops while-loop infinite

我的程序保持seg错误并使用gdb运行直到它进入无限循环。我无法弄清楚为什么会这样做,有人可以帮助我吗?

char tmpstring[1024];
    char* fileName;
    off_t size;
    char* pos;
    char *token;
    int total = 0;
    char* kiloCheck;
    char* tstallCheck;
    char* tmomCheck;

while (fgets(tmpstring, 1024, stdin)) 
    {
        fileName = tmpstring;
        //remove newline
        if ((pos=strchr(fileName, '\n')) != NULL)
            *pos = '\0';

        token = strtok(fileName, s);

        //walk through tokens
        while(token != NULL){

            size = filesize(token);
            total += size;

            token = strtok(NULL, s);
        }

    }

0 个答案:

没有答案