Thread: Phone Book

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    6

    Question Phone Book

    Hi all! I have a phone book program here which I will admit is not of my hand, but I have modified it a little bit, but it won't work in my compiler. What should I do??? It is attached
    Last edited by FerrariF12000; 12-09-2003 at 01:03 AM.

  2. #2
    Registered User
    Join Date
    Nov 2003
    Posts
    4
    Code:
    exit();

    Code:
    exit(0);

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Did it compile before you started modifying it?

    How many changes did you make before trying to compile it again?

    > What should I do
    Go back to your original source and make fewer changes before pressing compile.
    Then you will have fewer mistakes to worry about, and more idea of where the mistakes are
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Dec 2003
    Posts
    24
    Please Indent the code next time when you upload,

    some of the errors are

    1) character variable cannot be initialized to NULL pointer

    Code:
    s.homec = '\0'; // NULL is used only to initialize pointers
    s.offc = '\0'; // It needn't be '\0' it can be any character
    s.cellc = '\0';
    2) To find whether the char variable isn't used, the code checks whether this variable

    corresponds to the initial value (see below).

    Code:
    if(s.homec == NULL) // NULL has to be '\0'
         printf("\tHome Phone : %-12.0lf",s.homei);
    3) Instead of using fflush(stdin) to flush buffer (which doesn't serve any purpose), use a single

    space after '"' in scanf statement, as in the code below

    Code:
    scanf(" %s",s.fname);
    Leaving a single space indicates the compiler to get a fresh input and not from the standard

    input buffer.

  5. #5
    Registered User
    Join Date
    Nov 2003
    Posts
    6
    Originally posted by Salem
    Did it compile before you started modifying it?

    How many changes did you make before trying to compile it again?

    > What should I do
    Go back to your original source and make fewer changes before pressing compile.
    Then you will have fewer mistakes to worry about, and more idea of where the mistakes are
    Nope, I actually didn't modify any of the source just some of the text, yeah I would be very careful if I did modify the source. When I got the program, it never compiled with my compiler, but it did have an already compiled version, but I needed to modify it sooooo that is why I am here.


    Thanks all, I am going to try all of those things you guys said.

  6. #6
    Registered User
    Join Date
    Nov 2003
    Posts
    6
    Well guys I got it to run pretty well, except I cant delete the entries I put on my computer, would you check to see if it works okay on ur guy's comps??? please....

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Seems OK to me (in the sense that it runs and deletes stuff).

    I started off by deleting the pbook.dat

    Some points
    1. fp = fopen("pbook.dat", "rb++");
    ++ is not a mode

    2. scanf(" %lf", &s.celli);
    It's just %f for floats
    Besides, using floats to store phone numbers sucks, you should really store them as strings.
    Especially if you want to preserve any leading zeros.

    Your main() is 300 lines long, use some functions man.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Nov 2003
    Posts
    6
    haha! yup, that's one of the reasons I didnt take the credit for making it. To me it looks extremely old-fashioned with ancient code. Anyway I will be messing with it tomorrow so ill let u no how that goes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Phone book
    By Nightmaresiege in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2008, 05:12 PM
  2. a phone book program
    By mackieinva in forum C Programming
    Replies: 2
    Last Post: 09-19-2007, 06:31 AM
  3. phone book directory 2
    By arangawawa in forum C Programming
    Replies: 4
    Last Post: 08-01-2003, 05:32 PM
  4. Books on C and C++
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-28-2002, 04:18 PM
  5. Phone Class
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 03-30-2002, 07:42 AM