菜鸟问题,可能。我查看了其他答案,并尝试了他们所做的事情。但我仍然每次都收到错误。这是我的凯撒密码程序的第一个片段。
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main()
{
char message[81];
char cipher[81];
do
{
printf("Enter a message: ");
scanf("%[^\n]", &message);
//scanf("%s", &message) = error as well
printf("Test"); //to see if it prints. doesn't print, so seg fault must be on above line
if (!isalpha(message))
{
printf("Invalid input. Enter only letters.\n");
}
else
{
valid = 1;
}
} while (valid == 0);
// ...
作为输入,我将输入任何内容 - 一个字符串、一个字符、一个数字等,但仍然会出现段错误。
我正在使用 -W -Wall -ansi -pedantic 编译我的代码,并且没有收到与段错误相关的错误或警告。