有人能告诉我为什么我会得到 sigsegv 吗?
#include <stdio.h>
#include <string.h>
int main ()
{
char szInput[256];
printf ("Enter a sentence: ");
fgets (szInput, 256, stdin);
size_t n = (unsigned)strlen(szInput);
printf ("The sentence entered is %ld characters long.\n", n);
return 0;
}
当我运行它时会出现段错误。
unix>strlen_ex
Enter a sentence: foo bar burr
Segmentation fault