strcpy problems.

I do need some help. I don't know if anyone here could help me out about this but here's my issue;

I have an array tline[10 (the number of lines allowed) ][200 (the number of characters allowed) ] that has 4 strings in it. I need to feed these 4 strings into a char array. I made a second char array copy[10][200] to copy the string into the char array. This is the bit of code that I'm using

for(int j=0; j<NLINES; j++)
for(int h=0; h<LMAX; h++)
strcpy(copy[j][h],tline[j][h].c_str);

and these are the two errors I'm getting:
error C2228: left of '.c_str' must have class/struct/union
error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'

Please I hope someone can help me out with this. This is a huge issue that needs to be overcome before continuing with my project.

EDIT: I no longer receive error C2664, I don't know what I did but it's seemed to righted itself
Last edited on
The type of tline[j][h] is char. char is not a struct/class/union and therefore cannot have a member named "c_str".

Note also that the type of copy[j][h] is also char.

strcpy takes two parameters -- one is const char* and the other char*. Both of your parameters are chars (after fixing the above compile error). This should give you a hint that something else is wrong with your inner for loop/strcpy combination.
I'm having a difficult time with Jsmiths explanation. I've done what I think is changed tline and copy as follows to match his description:

const char* copy[NLINES][LMAX]

char* tline[NLINES][LMAX]

but I still recieve the same error. that .c_str must have class/struct/union. I don't recognize what this is supposed to signify.

I'm missing something here.
Last edited on
The syntax "a.b" is used when a variable "a" has a type that is a struct/class/union which contains a member "b".

In your case "a" is char. char does not have a member "c_str".

You are perhaps confusing C-style strings (char*) with the C++/STL string class.
The string class contains a member function c_str() which returns a C-style representation of the contained string.

You will need to remove ".c_str". Once you do this, your code still won't work, because you've now declared two two-dimensional arrays of C-strings. You wanted two one-dimensional arrays of C-strings. Your declarations of copy and tline were correct in the first place, but your inner for loop is wrong.
Topic archived. No new replies allowed.