Link to home
Start Free TrialLog in
Avatar of kuntilanak
kuntilanakFlag for United States of America

asked on

is this valid in both C and C++?

char *forStrings[2000];
strcat(forStrings,"\n     irSTRING string(s");


I tried to compile it using gcc and it gives me error :

:1371: warning: passing argument 1 of âstrcatâ from incompatible pointer type
Avatar of Infinity08
Infinity08
Flag of Belgium image

forStrings is basically a pointer-to-pointer-to-char, not a pointer-to-char as expected by strcat.

Did you mean :
char forStrings[2000] = "";
strcat(forStrings,"\n     irSTRING string(s");

Open in new window

no
Avatar of kuntilanak

ASKER

isn't that just similar with:

char forStrings[2000]
char *forStrings[2000] is not the same as char forStrings[2000]. The first is an array of 2000 pointers-to-char. The second is an array of 2000 char's.
Similar, except for the initialization, without which it is not guaranteed that forStrings will be validly null terminated
and when you do:

char forStrings[2000] =  " ";

you're basically declaring an array of 2000 pointers to char?
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok, thanks guys