string copy problem

K

kk

I wanna initialize a 3D character string array with a string "abc" but the
above VC 6.0++ compiler failed to do so.

what's the problem of the below codes and how to modify it?


char interface_aanum[10][100][4];

for (int k=0; k<10; k++)
for (int i=0; i<100; i++)
strcpy(interface_aanum[k], "abc");



error C2107: illegal index, indirection not allowed
error C2664: 'strcpy' : cannot convert parameter 1 from 'char (*)[4]' to
'char *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
 
J

Jack Klein

I wanna initialize a 3D character string array with a string "abc" but the
above VC 6.0++ compiler failed to do so.

what's the problem of the below codes and how to modify it?


char interface_aanum[10][100][4];

for (int k=0; k<10; k++)
for (int i=0; i<100; i++)
strcpy(interface_aanum[k], "abc");



error C2107: illegal index, indirection not allowed
error C2664: 'strcpy' : cannot convert parameter 1 from 'char (*)[4]' to
'char *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast


The error message above indicates that you are compiling this code as
C++, not C. Try
 
M

Martin Ambuhl

kk said:
I wanna initialize a 3D character string array with a string "abc" but the
above VC 6.0++ compiler failed to do so.

what's the problem of the below codes and how to modify it?


char interface_aanum[10][100][4];

for (int k=0; k<10; k++)
for (int i=0; i<100; i++)
strcpy(interface_aanum[k], "abc");


This code should work (on a C99 compiler), but for most C compilers
(C89|C90 compliant) something like
#include <string.h>

int main(void)
{
char interface_aanum[10][100][4];
int k, i;
for (k = 0; k < 10; k++)
for (i = 0; i < 100; i++)
strcpy(interface_aanum[k], "abc");

return 0;
}

is necessary. But your error messages
error C2107: illegal index, indirection not allowed
error C2664: 'strcpy' : cannot convert parameter 1 from 'char (*)[4]' to
'char *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast

indicate that you are not compiling this as C code, since the
diagnostics make no sense unless issued by a C++ compiler. C++ is not
C, but a different language. It is address in the newsgroup
news:comp.lang.c++
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,833
Members
47,380
Latest member
AlinaBlevi

Latest Threads

Top