我有一个简单的程序,它接收来自 3 个不同函数的输入,2 个返回整数,1 个返回一个字符,但第三个函数由于某种原因不扫描,它完全跳过了该步骤。
#include <stdio.h>
int get_height();
int get_length();
char get_symbol();
void draw_rectangle(int h, int l, char s);
int main () {
int h, l;
char s;
h = get_height();
l = get_length();
s = get_symbol();
draw_rectangle(h, l, s);
return 0;
}
int get_height() {
int i;
printf ("Please enter the height of the rectangle: ");
scanf ("%d", &i);
return i;
}
int get_length() {
int i;
printf ("Please enter the length of the rectangle: ");
scanf ("%d", &i);
return i;
}
char get_symbol() {
char i;
printf ("Please enter the symbol for the rectangle: ");
scanf ("%c", &i);
return i;
}
void draw_rectangle(int h, int l, char s) {
printf ("%d %d %c", h, l, s);
}
当我运行它时,我可以扫描高度和长度,但它会打印提示以扫描字符,但随后会跳过用户输入并打印 h 和 l 的值,但不打印 s。我在这里想念什么?