Re: Having issues trying to copy an array
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Sat, 19 Aug 2006 14:38:35 -0400
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
.
- Follow-Ups:
- Re: Having issues trying to copy an array
- From: Barry Schwarz
- Re: Having issues trying to copy an array
- References:
- Having issues trying to copy an array
- From: Chad
- Having issues trying to copy an array
- Prev by Date: Re: Can I Trust Pointer Arithmetic In Re-Allocated Memory?
- Next by Date: Re: secure integer library
- Previous by thread: Re: Having issues trying to copy an array
- Next by thread: Re: Having issues trying to copy an array
- Index(es):
Relevant Pages
|