错误,缺少终止字符

时间:2013-05-05 19:10:45

标签: c syntax-error

我有这个缺少终止的角色,但我不确定它想要什么或需要什么。我相信它在第二次循环的内部。可以做些什么来解决这个问题。我正在尝试输入一个带有一串路径的文本文件。然后从那里我解析这个字符串并将其放到链接列表中。然后在之后创建一个搜索功能。

文本文件:path.txt

a/a1.txt
a/a2.txt
a/b/b3.txt
a/b/b4.txt
a/c/c4.txt
a/c/c5.txt
a/c/d/d6.txt
a/c/d/g
a/c/d/h
a/c/e/i/i7.txt
a/c/f/j/k/k8.txt

代码:

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

typedef struct sMyPath{
        char *element;
        struct sMyPath *next;
} tMyPath;


int main(void)
{
        FILE *pFile;
        pFile = fopen("path.txt", "r");
        char inputstr[1024];
        tMyPath *curr, *first = NULL, *last = NULL;

//get the text file, and put it into a string inputstr

        if (pFile != NULL)
        {
                while(!feof(pFile))
                {
                        fgets(inputstr, sizeof(inputstr), pFile);
                }
        fclose(pFile);
        }
        else
        {
                printf("Could not open the file.\n");
        }

//using tokens to get each piece of the string
//seperate directories and text files, put it into a link list

        char *token = strtok(inputstr, "\");
        while (token != NULL)
        {
        if(last == NULL){
                //creating node for directory
                first = last = malloc (sizeof (*first));
                first -> element = strdup (token);
                first -> next = NULL;
        } else {
                last -> next = malloc (sizeof (*last));
                last = last -> next;
                last -> element = strdup (token);
                last -> next = NULL;
        }
        token = strtok(NULL, "\");
        }




//ask user for txt file
        char pathU[20];
        printf("enter text file\n");
        gets(pathU);


//check if text file exist, if yes output entires in text file, else say no
        while(first != NULL)
        {
                if(strcmp (first -> element,pathU)==0)
                {
                        FILE *nFile;
                        char texxt[300];
                        nFile = fopen(pathU, "r");
                        while (!feof(nFile))
                        {
                                fgets(texxt, 300, nFile);
                                printf("Theses are the contents\n");
                                printf("%s", texxt);
                        }

                }

                else if(first == NULL)
                {
                        printf("invalid file name\n");
                }

                else
                {
                first = first -> next;
                }




        }

return 0;
}

错误:

search.c:36:33: warning: missing terminating " character
search.c: In function ‘main’:
search.c:36: error: missing terminating " character
search.c:37: error: expected expression before ‘while’
search.c:50:24: warning: missing terminating " character
search.c:50: error: missing terminating " character
search.c:95: error: expected declaration or statement at end of input

1 个答案:

答案 0 :(得分:12)

在第

char *token = strtok(inputstr, "\");

您需要使用"\\"指定一个反斜杠字符。

单个反斜杠被视为多字符escape sequence的开头。

相关问题