Why is printf only printing the first char of this array and not all of them?
char *member[8];
char *tag;// this points a lot of text. if i print htmtag, it works fine with a few lines of text printing out
for ( int x = 0; x < 8; x++ )
{
member[开发者_Go百科x] = tag[x+15];
}
printf("member: %s",member);
Why would the above only print out the first char in member and not the whole 7, if i printf on member[0]/member[1]/member[2] the values are stored there but the following is printed?
i.e
member: 1
and i wanted to print out
member: 1234567
member should be declared as:
char member[8];
not
char * member[8];
as it is an array of chars, not an array of char pointers
As you didn't post enough code, the following is a guess:
Your member
variable is not a char[]
but a wchar_t[]
or MS TCHAR[]
. That would make each element of the member
array larger than 1 char, so when printf
treats it as an array of char it'd see '1', '\0', '2', '\0'
and so on - printing the first 1
then stopping on the 0-byte.
精彩评论