从字面上看,现在只有两个小时的学习时间。我每天在一小时内使用Sams Teach Yourself C,并且我仅仅停留在第2课的一个看似简单的练习上。函数'fgets'的参数太少?
5.以下程序有什么作用? (输入,编译和运行它。)
/* ex02-05.c */ #include <stdio.h> #include <string.h> int main(void) { char buffer[256]; printf("Enter your name and press <Enter>:\n"); fgets(buffer); printf("\nYour name has %d characters and spaces!", strlen(buffer)); return 0; }
所以书后说,最终的结果应该让我进入和名称,并把它告诉我的空间和人物的数量。但是,我收到一个错误,指出“在第9行上函数fgets的参数太少”?
'fgets()'需要三个参数。时间。顺便说一句:首先查找它期望的参数*的类型*。 – wildplasser
https://linux.die.net/man/3/fgets – Kevin
['fgets'](https://linux.die.net/man/3/fgets)需要3个参数。第一个是字符缓冲区,其中应该存储检索到的信息,第二个是要读取的字符数,第三个是要从中读取的字符串。 – yano