小编God*_*629的帖子

"Sams自己C"中的示例使用"fgets"但返回错误

包含的代码完全不在书中,但它会返回错误.这本书有不正确的做法吗?我以前从未使用#include <string.h>过,#include <stdio.h>但我仍然不知道三个参数应该是什么.

#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;
}
Run Code Online (Sandbox Code Playgroud)

编译说

Semantic issue with (fgets( buffer ); - Too few arguments to function call, expected 3, have 1

Format string issue (strlen(buffer)); - Format specifies type 'int' but the argument has type 'unsigned long'
Run Code Online (Sandbox Code Playgroud)

c c++ compilation fgets

-2
推荐指数
2
解决办法
188
查看次数

标签 统计

c ×1

c++ ×1

compilation ×1

fgets ×1