c - Returning an array of char pointers -
I am trying to return an array of char *
in a function. The code is simplified in the case of a test, in which a four array is cloned, in which instead of changing the letters indicates those characters.
/ * * code.c * / #include & lt; Stdio h & gt; Four * mapcountercopy (four CEN []); Int main () {char cTest [] = {'c', 't', 's', 't'}; Four * CPT [] = MakePaperCopy (CTT); Printf ("% p% c", CPTist, * CPTST); Fflush (stdout); Return 0; } Char * makePointerCopy (char cIn []) {char * cOut [sizeof (cin) / sizeof (Cen [0])]; Int iCntr; (ICntr + 0; iCntr & lt; for sizeof (cin) / sizeof (Cen [0]); iCntr ++) [iCntr] = cIn + iCntr; Returning cottage; }
On the one hand, what the compiler has to say about this code snippet:
Invalid initial (but char * CPT [] = MakePaperCopy (CTT);
)
Why does this happen?
Because makes a copy of a copypoint
a four *
Is not a four * []
.
You should be able to change that line to:
char * cPTest = makePointerCopy (cTest);
More specifically, instead of a few things about the reasons, you receive this error message, it is that those who started the array need to stabilize in compile-time .
Even if the declaration file is not in the scope, it will be illegal in both C90 and C99. The C90 automatically creates the initial demand for compilation-time for ARA and registration. And for both C90 and C99, a letter array is required, in which a) a string literally, or b) a brace-attached initial list.
However, this type of mismatch is a real problem.
Comments
Post a Comment