【发布时间】:2016-02-01 19:58:26
【问题描述】:
当我试图调用一个函数时,到目前为止我尝试过的参数只是导致终端说“函数的参数太少”,而我可以说它想要写的参数来自当它被宣布。我已经阅读了一些关于此的不同文档以及调用参数是什么以及按值或按引用调用之间的区别,但我仍然无法找出问题所在。 下面是代码的主要部分,其中包含调用函数以及一些变量。
int main(int argc, char *argv[])
{//main()
char *listwords;
processfile(listwords); //<- this is the line that is causing the problem
WordList mylist;
initialiselist(&mylist);
addword(&mylist, createfillednode(listwords));
printlist(&mylist);
}//main()
下面是processfile()函数:
//process the file
void processfile(WordList *wordList, int argc, char *argv[])
{//process file
//file pointer
FILE *f;
//open the file
f = fopen(argv[1], "r");
//check it opened correctly
if(f == NULL)
{//if statement
printf("cannot read file\n");
}//if statement
fseek(f, 0, SEEK_END);
//declare variables
char *listwords;
long size = ftell(f);
char *token;
//seek beginning of file
fseek(f, 0, SEEK_SET);
//set the size of array to the file size
listwords = (char*)malloc(size+1);
listwords[size] = '\0';
//reads the data from the file
fread(listwords, size, 1, f);
int i;
for(i=0; (token = strsep(&listwords, " ")); i++)
{//for loop replace certain characters with spaces
if (token != ".")
{
//pointer from the token to the dictionary
wordList->token;
}else if (wordList->token != "!")
{
wordList->token;
}else if (token != "?")
{
wordList->token;
}else if (token != "\"")
{
wordList->token;
}else if (token != ","){
wordList->token;
}else
{
wordList->token;
}
//increment token to the next word
token++;
}//for loop replace certain characters with spaces
fclose(f);
return;
}//process file
谢谢。
【问题讨论】:
-
processfile采用 3 个参数。您正在通过 1。可能有什么问题? -
too.few.arguments.to.function。怎么不清楚?
-
processfile(listwords);-->processfile(listwords, argc, argv);,提供,WordList是char的 typedef。
标签: c