c语言scanf附加格式*,C语言的scanf语句格式
滿意答案
pihiac
2014.09.05
采納率:45%????等級:7
已幫助:460人
scanf語句的一般格式如下:
scanf("格式字符串", 地址,…);
scanf語句用"格式字符串"控制鍵盤讀入的方式。"格式字符串"中一般只包括格式說明符,它們與printf語句中的一樣,而"地址"是指變量在內存中的位置。我們看看下面的程序實例,它定義了一個int、float、char和char []變量,并使用了格式說明符:
程序2-4:
#include
#define MAX_WORD 20
void main()
{
int x;
float a;
char ch, empty;
char word[MAX_WORD]; printf("Enter an integer: ");
scanf("%d", &x); printf("Enter a float: ");
scanf("%f", &a); fflush(stdin); // 清空輸入緩沖區
printf("Enter a character: ");
scanf("%c", &ch); printf("Enter a string: ");
scanf("%s", word); printf("Your integer was: %d\n", x);
printf("Your float was: %f\n", a);
printf("Your character was: %c\n", ch);
printf("Your word was: %s\n", word);
}
【酷_酷_幣】為您服務...
20分享舉報
總結
以上是生活随笔為你收集整理的c语言scanf附加格式*,C语言的scanf语句格式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用 Socket 通信实现 FTP 客
- 下一篇: 阿里云公司简介