在C语言中,输入数据通常是通过`scanf`函数来实现的。下面是一些基本的输入示例:
1. 输入单个字符:
char ch;printf("Please input a character: ");scanf("%c", &ch);printf("You input: %c\n", ch);
2. 输入整数:
int num;printf("Please input a number: ");scanf("%d", &num);printf("You input: %d\n", num);
3. 输入浮点数(单精度):

float num1;printf("Please input a float number: ");scanf("%f", &num1);printf("You input: %f\n", num1);
4. 输入字符串:
char str;printf("Please input a string: ");scanf("%s", str);printf("You input: %s\n", str);
请注意,在使用`scanf`函数时,输入的数据会根据指定的格式控制字符串进行解析。如果输入的数据不符合格式,程序可能会产生未定义的行为。
另外,`gets`函数也可以用来读取字符串,但因为它不检查缓冲区溢出,所以使用起来存在安全风险。现代C语言编程推荐使用`fgets`函数代替`gets`。
