fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.  
  5. char firstname[20]; /* first name */
  6. char middle; /* middle initial */
  7. char lastname[20]; /* last name */
  8.  
  9. printf ("\nEnter first name: ");
  10. scanf ("%s", firstname);
  11.  
  12. printf ("\nEnter middle initial: ");
  13. scanf (" %c", &middle); /* note the space before the %c */
  14.  
  15. printf ("\nEnter last name: ");
  16. scanf ("%s", lastname);
  17.  
  18. /* print out the name to the screen */
  19. printf ("\n\nThe name read is: %s %c %s \n", firstname, middle, lastname);
  20.  
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 5288KB
stdin
Connie S Cobol
stdout
Enter first name: 
Enter middle initial: 
Enter last name: 

The name read is:  Connie S Cobol