Thread: struct function problem

  1. #1
    totalfreeloader
    Guest

    struct function problem

    hi,
    Im having problems how to declare a struct function prototype and how to call it in main
    eg

    code:
    _______________________________________

    struct PhoneBook
    {
    int Number;
    char Name[MAXNAMELENGTH + 1];
    };

    //Prototypes

    void Sort(struct PhoneBook [], int LISTSIZE); //Sorts the contacts in the list
    void Search(struct PhoneBook ); //Searchs list for a name and returns a bool value
    struct Add(struct PhoneBook []); //Adds a single contact to list
    struct Delete(struct PhoneBook []); //Deletes a single contact from list

    main()
    {
    struct PhoneBook List[MAXLISTSIZE] = {
    { 353871234567890, "Tom Crowe"}
    { 32432543543534, "Thomas Riddick"}
    };
    Search(PhoneBook List); //i think this is wrong

  2. #2
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    once you declare the stuct you don't have to declare it again.
    Code:
    struct PhoneBook List[MAXLISTSIZE]
    //should be
    PhoneBook List;// you declare an object with the name List of the
                              //type PhoneBook
    
    Search(PhoneBook List);
    //should be
    Search(List); //you have already decleared the type. The other
                        //should give you a compiler error
    There may be more mistakes but those are the ones I can see.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  3. #3
    totalfreeloader
    Guest
    thanks very much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. problem returning struct member from function
    By yukster in forum C Programming
    Replies: 6
    Last Post: 08-24-2003, 01:21 PM