2 dimensional strcpy err


R

Ross

char chain[10][300];


strcpy(chain[i+20], chain);


error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast


how to amend that?
 
Ad

Advertisements

G

Guy

strcpy((char*)chain + 300*(i+20) , (char*)chain + 300*i);


~ ªÑ²¼»ù®æ¦³¤É¦³¶^, ¶R½æ­n¯à©Ó¾á­·ÀI ~

~ Samba, more than a low cost File and Printer server ~

-- Let us OpenSource --
 
J

Jens.Toerring

Ross said:
char chain[10][300];
strcpy(chain[i+20], chain);

error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast
how to amend that?

First thing I would try to do in your case would be to invoke your
compiler in C and not C++ mode. Second, you should make sure that
you don't use array elements that don't exist. With the above 'i'
would have to be between -20 and -11 in order not to access an
element outside of the 'chain' array for the first argument to
strcpy(), but, on the other hand, 'i' has to be between 0 and 20
for the second argument - which it obviously can't be both at the
same time.
Regards, Jens
 
M

Martin Ambuhl

Ross said:
char chain[10][300];
strcpy(chain[i+20], chain);

error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast
how to amend that?

Use a C compiler. You are using a C++ compiler. If your product claims
to compile both C and C++, then it has different ways of invoking it for
the two different languages. Read the documentation.
 
K

Keith Thompson

Ross said:
char chain[10][300];


strcpy(chain[i+20], chain);


error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast


As others have mentioned, you should invoke your compiler in C mode
rather than C++ mode, but I don't think that's your problem.

The first argument to strcpy is of type char[300], which is converted
to char*. The compiler is saying that it's of type char. The only
explanation I can think of is that the code you posted isn't the same
as the code you're trying to compile.

If you post a code sample, you need to cut-and-paste the *exact* code;
we can't guess what your actual code looks like.
 
J

Jack Klein

strcpy((char*)chain + 300*(i+20) , (char*)chain + 300*i);

There are so many things wrong with this post that I'm not even going
to try to correct them.

To anyone reading this post: DON'T DO THIS.
 
Ad

Advertisements

E

Emmanuel Delahaye

Ross wrote on 25/12/04 :
char chain[10][300];

strcpy(chain[i+20], chain);

error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast


First of all, be sure you are using a C compiler. The file extension
should be .c (lowercase) and not .cpp or .C (uppercase).

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++
 
Ad

Advertisements

A

Andrey Tarasevich

Ross said:
char chain[10][300];


strcpy(chain[i+20], chain);


error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast


how to amend that?


First of all - post real code. The code you provided cannot result in
the above error message.
 

Top