Guest User

Little program

a guest
Mar 22nd, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. /*
  2.  
  3. Name & Phone number program
  4.  
  5.  
  6. Needs a total of 2 arrays, one for the name and one for the phone number.  
  7.  
  8.  
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <string.h>
  13. int main(void)
  14. {
  15.     int i;
  16.     char names[5][20];
  17.     char phoneNumber[5][11];
  18.     int select;
  19.    
  20.     printf("Please enter names : \n\n");
  21.    
  22.    
  23.     for ( i = 0 ; i < 5 ; i++ )
  24.     {
  25.         fgets( names[i], sizeof names[i], stdin );
  26.         names[i][strlen(names[i]) - 1] = '\0'; //just subtract 1 to overwrite the '\n' with null terminator
  27.     }
  28.    
  29.     puts("Please enter phone numbers : ");
  30.    
  31.     for ( i = 0 ; i < 5 ; i++ )
  32.     {
  33.         fgets( phoneNumber[i], sizeof phoneNumber[i], stdin );
  34.         phoneNumber[i][strlen(phoneNumber[i]) - 1] = '\0'; //just subtract 1 to overwrite the '\n' with null terminator
  35.     }
  36.    
  37.     puts("Which array would you like? ");
  38.    
  39.     scanf("%i", &select);
  40.    
  41.     printf("name %i is   : %s\n", select, names[select]);
  42.     printf("number %i is : %s\n", select, phoneNumber[select]);
  43.    
  44.     printf("\n");
  45.    
  46.     return 0;
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment