c言語scanf入力文字_C言語でscanf()文を使用して整数、浮動小数点、文字値を入力します.

3032 ワード

c言語scanf入力文字
We have to read tree values: integer, float and then character using only one scanf() function and then print all values in separate lines.
ツリー値:整数、浮動小数点数、文字を1つのscanf()関数で読み出し、すべての値を個別の行に印刷するだけです.
Example:
例: Input: Input integer, float and character values: 10 2.34 X Output: Integer value: 10 Float value: 2.340000 Character value: X Before moving to the program, please consider the scanf() statement,
プログラムに移動する前にscanf()文を考慮してください. scanf ("%d%f%*c%c", &ivalue, &fvalue, &cvalue); Here, %*c is used to skip the character to store character input to the character variable, almost all time, character variable’s value will not be set by the given value because of the "ENTER"or "SPACE"provided after the float value, thus, to set the given value, we need to skip it.
ここで、%*cは、入力された文字を文字変数に格納するために文字をスキップするために使用されます.ほとんどの時間、浮動小数点値の後に「Enter」または「SPACE」が提供されるため、文字変数の値は所定の値で設定されません.したがって、所定の値を設定するにはスキップする必要があります.
To learn more, read: Skip characters while reading integers using scanf() in C
詳細については、C言語でscanf()を使用して整数を読み込むときに文字をスキップするを参照してください.
Program:
プログラム:# include <stdio.h> int main () { int ivalue; float fvalue; char cvalue; //input printf("Input integer, float and character values: "); scanf ("%d%f%*c%c", &ivalue, &fvalue, &cvalue); //print printf ("Integer value: %d
", ivalue) ; printf ("Float value: %f
", fvalue) ; printf ("Character value: %c
", cvalue) ; return 0; }
Output
しゅつりょくりょうInput integer, float and character values: 10 2.34 X Integer value: 10 Float value: 2.340000 Character value: X 翻訳:https://www.includehelp.com/c-programs/input-integer-float-and-character-values-using-one-scanf-statement.aspx
c言語scanf入力文字