Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

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
0
kuntilanak
Asked:
kuntilanak
  • 3
  • 3
  • 3
2 Solutions
 
Infinity08Commented:
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

0
 
ozoCommented:
no
0
 
kuntilanakAuthor Commented:
isn't that just similar with:

char forStrings[2000]
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Infinity08Commented:
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.
0
 
ozoCommented:
Similar, except for the initialization, without which it is not guaranteed that forStrings will be validly null terminated
0
 
kuntilanakAuthor Commented:
and when you do:

char forStrings[2000] =  " ";

you're basically declaring an array of 2000 pointers to char?
0
 
Infinity08Commented:
>> and when you do:
>> 
>> char forStrings[2000] =  " ";
>> 
>> you're basically declaring an array of 2000 pointers to char?

No, that's an array of 2000 char's. An array of char's is commonly called a string, so this is a string of 1999 characters (+ one character for the terminating '\0').
That string is initialized to the string " ".
0
 
ozoCommented:
when you do:

char forStrings[2000] =  " ";

you're basically declaring one pointer to an array of 2000 char, starting with {' ', '\0'}
0
 
kuntilanakAuthor Commented:
ok, thanks guys
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now