Thread: help with phonebook: commands and assigning numbers/letters

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    42

    help with phonebook: commands and assigning numbers/letters

    I've got my code so that when I enter "1" it adds an entry, "2" to delete entry, and "3" to print the pb.... I want the commands to be in letters as seen in the printf. I'm not sure how to put into arrays..


    Code:
    #include <stdio.h>
    #include <string.h>
    
    
    
    
    
    
    int i;
    int number_of_entries;
    typedef struct{
            char first [15];
            char last [15];
            char phone [15];
            }phonebook;
    
    
    main (){
    phonebook entry[50];
    int response;
    
    
    printf("\n\tPhonebook\n\n");
    printf("(A)Add an entry\n");
    printf("(D)Delete an entry\n");
    printf("(P)print the phonebook\n");
    printf("(Q)quit\n");
    printf("Enter selection: ");
    scanf("%d", &response);
    
    
    switch (response){
    case 1:
         number_of_entries++;
         printf("Enter First Name: ");
         scanf("%s", entry[i].first);
         printf("Enter Last Name: ");
         scanf("%s", entry[i].last);
         printf("Enter Phone Number: ");
         scanf("%s", entry[i].phone);
         return 0;
         break;
    
    
    case 2:
    
    
    
    
    
    
    case 3:
         for(i; i<number_of_entries; i++){
         printf("%s, %s, %s", entry[i].last, entry[i].first, entry[i].phone);  }
         return 0;
         break;
                     }
    system("pause");
    return 0;
    }

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    You should be putting your data into entry[number_of_entries] rather than entry[i].

    edit- also, you need to initialise number_of_entries
    Last edited by TheBigH; 12-07-2011 at 04:37 PM. Reason: ...
    Code:
    while(!asleep) {
       sheep++;
    }

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Line 53 ... what is the value of i at the start of that loop ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. converting letters into numbers.
    By xforevertink in forum C++ Programming
    Replies: 8
    Last Post: 07-20-2009, 12:12 AM
  2. converting numbers to letters
    By sh4k3 in forum C Programming
    Replies: 6
    Last Post: 06-10-2007, 07:15 PM
  3. Numbers to Letters
    By flip114 in forum C Programming
    Replies: 5
    Last Post: 09-24-2003, 03:18 AM
  4. Letters-numbers
    By wuzzuppy_123 in forum C++ Programming
    Replies: 4
    Last Post: 05-09-2003, 02:51 PM
  5. scanning for numbers - not letters
    By volk in forum C++ Programming
    Replies: 7
    Last Post: 04-07-2003, 03:44 PM