Closed Thread
Results 1 to 3 of 3

Thread: Phone Book Program

  1. #1
    big-tony is offline Learning Programmer
    Join Date
    Jan 2009
    Location
    Tennessee
    Posts
    42
    Rep Power
    0

    Red face Phone Book Program

    This is what i'm doing

    Create a program that uses a structure array to hold contact
    information for your friends. The program should allow the
    user to enter up to five friends and print the phone book’s
    current entries. Create functions to add entries in the phone
    book and to print valid phone book entries. Do not display
    phone book entries that are invalid or NULL (0).


    Whenever I compile the program I can enter 5 numbers and names however, once the results show they are ALL the same RANDOM number..

    Where have I went wrong? also, how could I make it where you could put dashes in the inputted and outputted numbers without messing it up?

    Here is my Code:

    Code:
    struct phonebook
    {
    char name[100];
    long int phone;
    };
    
    int main()
    {
    struct phonebook myphonebook[5];
    int i;
    for(i=0;i<5;i++)
    {
    printf("\n Enter name of friend:-\n");
    scanf("%s",&myphonebook.name );
    printf("\n Enter phone number of friend:-\n");
    scanf("%ld",&myphonebook.phone );
    }
    for(i=0;i<5;i++)
    {
    printf("\n Friend name %s phone number is %ld \n",myphonebook.name,myphonebook.phone);
    }
    return 1;
    }

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,448
    Blog Entries
    74
    Rep Power
    143

    Re: Phone Book Program

    You aren't subscripting your myphonebook array on your scanf()'s
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    kiddies is offline Programmer
    Join Date
    May 2009
    Posts
    129
    Rep Power
    0

    Re: Phone Book Program

    hello.....im newbie here...thats script not complete r8...can u give me a complete script for learn...couse i dont understand if just lil script like that....

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 12-18-2010, 12:06 AM
  2. program from book doesn't work
    By thatsme in forum C and C++
    Replies: 7
    Last Post: 02-12-2010, 12:10 AM
  3. Error on My Basic Program Copied from Programming Book
    By kidcash in forum General Programming
    Replies: 6
    Last Post: 01-30-2008, 09:03 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts