#include<stdio.h>
#include<string.h>
void main()
{
char a,b,c;
printf("Enter alien names:\n");
scanf("%s\n%s\n%s\n",a,b,c);
printf("The alien names are %s, %s and %s. A meteor hit %s's spaceship. A star scratched %s\'s spaceship. But %s fixed %s and %s\'s spaceships. The three became friends and are from the planet BYG (which means BLUE YELLOW GREEN)",a,b,c,a,b,c,a,b);
}
我在这里遇到运行时错误的具体原因是什么?
最佳答案
要解决这个问题,您应该简单地考虑使用字符串(字符数组)来包含不同的名称。
这是一个如何做到这一点的例子:
void main()
{
// The string "a" can contain up to 100 symbols (chars).
char a[100];
printf("Enter an alien name:\n");
scanf("%s",a);
printf("The alien name is %s.", a);
}
“char a”和“char a[100]”之间的区别在于,在第一种情况下,变量“a”对应于单个字符,而在第二种情况下,它对应于一个字符串 - 一个字符数组,可以最多包含 100 个字符。
关于c - 我在这里遇到运行时错误的具体原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44893293/