Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name & Phone number program
- Needs a total of 2 arrays, one for the name and one for the phone number.
- */
- #include <stdio.h>
- #include <string.h>
- int main(void)
- {
- int i;
- char names[5][20];
- char phoneNumber[5][11];
- int select;
- printf("Please enter names : \n\n");
- for ( i = 0 ; i < 5 ; i++ )
- {
- fgets( names[i], sizeof names[i], stdin );
- names[i][strlen(names[i]) - 1] = '\0'; //just subtract 1 to overwrite the '\n' with null terminator
- }
- puts("Please enter phone numbers : ");
- for ( i = 0 ; i < 5 ; i++ )
- {
- fgets( phoneNumber[i], sizeof phoneNumber[i], stdin );
- phoneNumber[i][strlen(phoneNumber[i]) - 1] = '\0'; //just subtract 1 to overwrite the '\n' with null terminator
- }
- puts("Which array would you like? ");
- scanf("%i", &select);
- printf("name %i is : %s\n", select, names[select]);
- printf("number %i is : %s\n", select, phoneNumber[select]);
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment