我正在尝试打印 gets() 函数在 C 中返回的内容。
我尝试了各种格式说明符,但似乎没有任何帮助。
char a[100];
char (*p)[100];
p=gets(a);
printf("%s",p);
它只是说段错误。
最佳答案
The gets function returns [the original argument] if successful. If end-of-file is encountered and no characters have been read into the array, [...] a null pointer is returned. If a read error occurs during the operation, [...] a null pointer is returned.
因此,gets()
函数(C99 或更早版本)返回其参数或 NULL
。
请注意,它是 marked obsolescent in C99 (2007 TC)和 removed from the Standard in C11 .
<小时/>char a[100];
char *p;
p = gets(a); // assign a (&a[0]) to p if no errors
printf("%c is the same as %c\n", a[0], p[0]);
关于c - 如何检查 C 中的 gets() 函数返回什么值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57344310/