Thread: arrays

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    18

    arrays

    i have this array
    Code:
    char subcode[CODELENGTH];
    say the value JJ123

    i also have
    Code:
    char subjectcode[MAXSUBJECTS][CODELENGTH];

    i have this for loop and it doesnt work

    Code:
    inFile>>subcode;
    cout<< "Subject Code" << subcode;
    for(int p=0;p<CODELENGTH;p++)
    {
    subjectcode[MAXSUBJECTS][0+p] = *subcode; 
    cout << subjectcode[0][CODELENGTH];
    }
    can some1 help me please

    also if i enter it all in a 2d array.. is it possible to search it.. and retrieve the first line..

    that is.. supose the array ends up being

    J1234
    J2314
    J1235

    if some1 types J1234 will i be able to search it and retrieve ...

    thankyou
    Last edited by chizzy; 10-30-2002 at 03:09 PM.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Can you post some code, your question is a little unclear.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    array2 is defined as char, not char *.

    array2[0][1 + i] = array[0];

    Kuphryn

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    18
    i have add more code aboe

    thankx

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Code:
    //obtain subcode from file
    inFile>>subcode;
    //verify subcode read in correctly
    cout<< "Subject Code" << subcode;
    
    //now read in subcode to subjectcode, one char at a time
    for(int r = 0; r < MAXSUBJECTS; r++)//determines which subcode in subjectcode will be the target for storage
    {
      //loop to read in one char at a time from file data to subjectcode.
      for(int p=0;p<CODELENGTH;p++)
      {
         subjectcode[r][p] = subcode[p]; 
      }
    
         //null terminate current subjectcode after all pertinent char
         // have been copied to it
          subjectcode[r][p] = '\0';
    
         //then prove you copied it correctly
         cout << subjectcode[r];
    }
    to determine if a given subcode already exists in subjectcode use a loop to compare each subcode already in subjectcode to the desired subcode using strcmp().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM