Results 1 to 3 of 3

Thread: c++ help cont

  1. #1
    Registered+
    Join Date
    Dec 2004
    Posts
    49
    Thanks
    0
    Thanked
    0 times in 0 posts

    c++ help cont

    Any help with this pls,?
    ive got a c++ prgram which saves a grade but As Well as saving a grade i also need to save a name in an array . ive tried all sorts of things eg
    trying to add a name input into the current getGrade function-but doesnt work cos its not an int
    tried making a new function but couldnt work out how to format the array eg what to save inside it-and when to call things.


    Any help would be appreciated
    Ive tried lookin on examples and c++.com-cant see anything
    Ta
    Last edited by hegaroo; 21-12-2004 at 11:51 AM. Reason: cos

  2. #2
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    I would say remove the static array for grades you have and use a structure instead:

    Code:
    typedef struct {
                         char forename[50];
                         char surname[50];
                         int grade;
    }GRADES;
    
    GRADES grade;
    To err is human. To really foul things up ... you need a computer.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    13
    Thanks
    0
    Thanked
    0 times in 0 posts
    Quote Originally Posted by yamangman
    I would say remove the static array for grades you have and use a structure instead:

    Code:
    typedef struct {
                         char forename[50];
                         char surname[50];
                         int grade;
    }GRADES;
    
    GRADES grade;
    While I agree with this, I'd also suggest that you don't specify hard-coded numeric values for your array size. Instead, use #define's like this:

    Code:
    #define DEF_MAX_FORENAME_LEN 50
    #define DEF_MAX_SURNAME_LEN 50
    When using them in your array declaration, some people like to specify the additional 1 character explicitly (for the terminating null):

    Code:
    char forename[DEF_MAX_FORENAME_LEN + 1];
    This way, it makes it easier/neater to do any bounds checking before attempting, for example, copying a string to your array because you can simply check the length doesn't exceed DEF_MAX_FORENAME_LEN.

Thread Information

Users Browsing this Thread

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

Posting Permissions

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