我是编程新手。我只是想制作自己的程序来查找球体和圆柱体的体积和表面积。我无法弄清楚为什么这个程序在它到达其余代码之前一直崩溃。我猜这char*
可能是错误的,但我不明白为什么会这样。
int main()
{
char* solid;
char* unit;
printf("Welcome to the Center of Spheres and Cylinders!\n");
printf("Would you like to look at a Sphere or a Cylinder?: ");
scanf("%s", solid);
if(solid == "Cylinder" || solid == "cylinder")
{
printf("You chose to look at a Cylinder.\n");
else if(solid == "Sphere" || solid == "sphere")
{
printf("You chose to look at a Sphere.\n");
它在我输入 .. 之后就崩溃了,当我输入scanf.
圆柱体或球体时它崩溃了。感谢您的帮助