【发布时间】:2016-10-02 18:26:27
【问题描述】:
所以我一直在研究一个可以找到形状区域的程序 我的编译器出现多个错误,说我正在比较 一个指针和一个整数,但我不是……至少我不认为我是。程序运行,但是当我输入我的字符串时,它崩溃了
这是我的代码
#include <stdio.h>
#include <math.h>
int main(void){
char str_1;
printf("Hello! This program will find the area of selceted figrues!\n");
printf("What is your shape? The only shapes that work are Triangles,\
Rectangles, and Circles\n");
scanf("%c", str_1);
do {
printf("That is an invalid input the only shapes that work are Triangles, \
Rectangles, and Circles\n");
scanf("%c", str_1);
}
while(str_1 != "circle", "rectangle", "triangle");
if (str_1 == "circle") {
printf("What is the radius?\n");
scanf("%i");
}
}
【问题讨论】:
-
char-->char数组。 -
使用
strcmp()...... -
while(str_1 != "circle", "rectangle", "triangle");C 不会那样做。你用的是什么教材?我们将向您介绍适当的函数和逻辑运算符。 -
scanf("%c", str_1);->scanf(" %c", &str_1);在格式字符串中添加一个空格并在str_1上使用&运算符。 -
相信编译器。它比你更懂 C。