Re: Having issues trying to copy an array



Chad wrote:

I'm want
static char *output[BUFF];

to hold the modified string "tel chad"

However, when I debug it,
static char *output[BUFF]
holds the ascii value of the strng, and not the string itself.

Here is what I have. I know gets(), strcat strcpy() shouldn't be used.
I just wrote the program to isolate the problem I'm having.

#include <stdio.h>
#include <stdlib.h>

#define BUFF 20

int main(void) {
char name[BUFF];
static char *output[BUFF];
int count = 2;

char tel[] = "tel ";
char *msg_list[] = {" apple", " orange", " grape" };

printf("Enter the target persons username \n");
gets(name);

/* tel = "tel chad"*/
strcat(tel,name);
printf("%s \n", tel);

strcpy(&output[1], tel);

/*strcat(tel,msg_list[1]);*/
/* printf("%s \n", output[1]);*/

return 0;
}

output is an array of BUFF pointers to char, none of which have
been initialized. In addition the thing does not even compile
cleanly:

[1] c:\c\junk>cc junk.c
junk.c: In function `main':
junk.c:12: warning: initialization discards qualifiers from pointer
target type
junk.c:12: warning: initialization discards qualifiers from pointer
target type
junk.c:12: warning: initialization discards qualifiers from pointer
target type
junk.c:18: warning: implicit declaration of function `strcat'
junk.c:21: warning: implicit declaration of function `strcpy'
junk.c:21: warning: passing arg 1 of `strcpy' from incompatible
pointer type
junk.c:9: warning: unused variable `count'
junk.c:12: warning: unused variable `msg_list'


--
"The power of the Executive to cast a man into prison without
formulating any charge known to the law, and particularly to
deny him the judgement of his peers, is in the highest degree
odious and is the foundation of all totalitarian government
whether Nazi or Communist." -- W. Churchill, Nov 21, 1943


.



Relevant Pages

  • Re: Arrays issue
    ... x.c:158: warning: format argument is not a pointer ... size NAMESIZE) of "char". ... encountered a service with extra aliases, ... It happens to be an object of type "pointer to pointer to char" ...
    (comp.lang.c)
  • Re: Simple question on Pointers
    ... Why does the latter example give the following warning? ... "pointer to pointer to char". ... The first expression doesn't group like the second. ...
    (microsoft.public.vc.language)
  • Re: warning: return makes integer from pointer without a cast
    ... That silences the warning, but the warning wasn't the problem. ... strdup returns a result of type char*. ... pointer to integer. ... adding a cast to silence a warning is seldom a good ...
    (comp.lang.c)
  • Re: Confused by const
    ... meow(const char * const *p) ... Why is the call to meowgenerate a warning: ... The rule for pointer ...
    (comp.lang.c)
  • Re: hash.h warnings
    ... enough about this type of warning to fix it. ... After looking at the source it appears that part of the problem stems from the fact that p is an unsigned char pointer, where ep is a signed char double pointer. ... So, if you modified buf or ep to be compatible with one another, you probably wouldn't get this warning.. ...
    (freebsd-hackers)