work it out

This is a discussion on work it out within the C++ Programming forums, part of the General Programming Boards category; ok i have a struct within a struct and am using linked lists, e.g struct subject { char onesubject [MAXNAME]; ...

  1. #1
    kEEN_C
    Guest

    Unhappy work it out

    ok i have a struct within a struct and am using linked lists,

    e.g

    struct subject
    {
    char onesubject [MAXNAME];
    int num;
    }

    struct Result
    {
    long id;
    subject students [MAXSUBJECTS];
    }


    do i use two pointers?
    if so could you show me an example of how i could access data members of another struct within a struct.

    Another question, what could i use to detect say ,J1234 detect the 1st number within the an array that contains those types of subject codes?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    23
    Well, let's see:

    Say you have-

    Result r;

    So the first first student would be:

    r.students[0]

    and the first charachter of the subject of the first student would be:

    r.students[0].onesubject[0];

    Searching for the first digit of a subject would require a loop:

    int i = 0;
    const char* subject = r.students[0].onesubject;
    const int length = strlen(subject);
    for(;i<length;++i)
    {
    if(isdigit(subject[i])
    {
    break;
    }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 08:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 11:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 11:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 05:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21