我基本上是在尝试从文件中读取数据而忽略所有非字母字符,并且非字母前面的任何字符都将被视为单词的结尾,并应插入到trie中。有任何想法吗? 下面是我当前的代码,它正在获得一个seg错误
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
char input;
void readDict(FILE *dict_file)
{
int line = 0;
char curr;
while ( (curr = fgetc(dict_file))!= EOF)
{
if(isalpha(curr))
{
strcpy(input,curr);
}
}
}
int main(int argc, char * argv[])
{
if (argc < 2)
printf("invalid input");
else
{
FILE *pFile = fopen(argv[1],"r");
readDict(pFile);
}
return 0;
}
答案 0 :(得分:1)
分段错误由strcpy
生成。您必须将char *
传递给strcpy
作为参数。在您发布的代码中,input
和curr
都属于char
类型。
阅读http://www.cplusplus.com/reference/cstring/strcpy/以了解如何使用strcpy
。