-
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
-
Can you post some code, your question is a little unclear.
-
array2 is defined as char, not char *.
array2[0][1 + i] = array[0];
Kuphryn
-
i have add more code aboe
thankx
-
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().