Sunday, August 13, 2017

C programming;Lesson 5: Getting keyboard input

To load data from the keyboard, use the scanf function.
The shape of the function is:  
                                               scanf ("list_of_formats", list_of_variable_address);

The variable address can be obtained by using the operator & before the variable name, while the variable formats are the same as the case of printing data on the screen. 
An example of loading a variable from the keyboard: 
                                                                                      int a;
                                                                                      scanf ("%d", &a);

An example of loading multiple keystrokes variables: 
                                                                                     int a; 
                                                                                     float b; 
                                                                                     scanf ("%d%f", &a, &b); 
                                                                                     scanf ("%d,%f", &a, &b);

1 comment: