C Programming Tutorial – 8 – Get data from keyboard scanf():


  • // scanf() :  get data from keyboard or user.
  • // Use & before all of the variables, except Array variables.


#include <stdio.h>
#include <stdlib.h>

int main()

char firstname[20];
char lovename[20];
int NumberOfBaby;
printf(“What is your name?\a\n”);
scanf(“%s”,firstname);                                                           // scanf get data from keyboard or user
printf(“What is your love name?\a\n”);
printf(“How many baby you will have?\a\n”);
scanf(“%d”, &NumberOfBaby);                     // Use & before all of the variables except Array variables.
printf(“%s and %s are in love. They will have %d babies\n”, firstname,lovename ,NumberOfBaby );

return 0;