char[] problem
-
I have array of characters.I want to send it as a parameters to other function and this character may contain '0',when I do it like the code below,it only pass up to '0' character.
char c[1000];
for(int i ; i<1000; i++)
c[i] =value;
myfunc(c);Before the last line it containcorrect value,but in myfunc() it contain only value up to '0' value.So how can I pass it correctly? Mazy No sig. available now.
-
I have array of characters.I want to send it as a parameters to other function and this character may contain '0',when I do it like the code below,it only pass up to '0' character.
char c[1000];
for(int i ; i<1000; i++)
c[i] =value;
myfunc(c);Before the last line it containcorrect value,but in myfunc() it contain only value up to '0' value.So how can I pass it correctly? Mazy No sig. available now.
-
I have array of characters.I want to send it as a parameters to other function and this character may contain '0',when I do it like the code below,it only pass up to '0' character.
char c[1000];
for(int i ; i<1000; i++)
c[i] =value;
myfunc(c);Before the last line it containcorrect value,but in myfunc() it contain only value up to '0' value.So how can I pass it correctly? Mazy No sig. available now.
What is the starting value for i? Hint: it ain't 0!
-
What is the parameter definition of myfunc()? Does it accept a pointer to char? myfunc(char *); Kuphryn
-
What is the starting value for i? Hint: it ain't 0!
-
I have array of characters.I want to send it as a parameters to other function and this character may contain '0',when I do it like the code below,it only pass up to '0' character.
char c[1000];
for(int i ; i<1000; i++)
c[i] =value;
myfunc(c);Before the last line it containcorrect value,but in myfunc() it contain only value up to '0' value.So how can I pass it correctly? Mazy No sig. available now.
-
DavidCrow wrote: What is the starting value for i? Hint: it ain't 0! Its 0. Its just miss-typing. :-D Mazy No sig. available now.
Miss-typing and omission are two different things:
char c[1000];
for(int i = 0; i<1000; i++)
c[i] =value;
myfunc(c); -
maybe the problem is the declaration of myfunc(), your upper code seems alright to me... is the declaration myfunc(char* c) ???? is the argument a pointer? greets, jason
-
jason99 wrote: is the argument a pointer? As I said before, NO. Mazy No sig. available now.
Since arrays decay immediately into pointers, an array is never actually passed to a function. Allowing pointer parameters to be declared as arrays is a simply a way of making it look as though the array was being passed. Therefore, any parameter declarations which "look like" arrays, e.g. f( char a[]) { ... } are treated by the compiler as if they were pointers, since that is what the function will receive if an array is passed: f( char *a) { ... } This conversion holds only within function formal parameter declarations, nowhere else. If the conversion bothers you, avoid it.
-
I have array of characters.I want to send it as a parameters to other function and this character may contain '0',when I do it like the code below,it only pass up to '0' character.
char c[1000];
for(int i ; i<1000; i++)
c[i] =value;
myfunc(c);Before the last line it containcorrect value,but in myfunc() it contain only value up to '0' value.So how can I pass it correctly? Mazy No sig. available now.