initial import
[staff/goc4/2018bti7061.git] / c-2-controlStructures / examples / inputsoutputs / inputs.c
1 #include <stdio.h>
2
3 main(){
4
5 puts("Tests of inputs of strings (scanf)");
6
7 /* Example 1 Scanf */
8 int i1;
9 double d1;
10 char c1;
11 puts("type an integer, a float and a char");
12 int res= scanf(" %d %lf %c",&i1,&d1,&c1);
13
14 printf(" i1=%d, d1=%lf c1=%c\n",i1,d1,c1);
15 printf("res=%d\n",res);
16
17 /* if input is : 1234 10.5 T
18 Output is i1=1234, d1=10.500000 c1=T
19 */
20
21 /* Example 2 Scanf */
22 int i2;
23 double d2;
24 char c2;
25 puts("type an integer (3 digits), a float (5 chars) and a char");
26 scanf(" %3d %5lf %c",&i2,&d2,&c2);
27 printf(" i2=%d, d2=%lf c2=%c\n",i2,d2,c2);
28 /* if input is : 1234 10.5 T
29 Output is: i2=123, d2=4.000000 c2=1
30
31 */
32
33
34
35
36 }