user370507
user370507

Reputation: 497

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[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

Upvotes: 2

Views: 6089

Answers (2)

Trent
Trent

Reputation: 13477

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

Upvotes: 6

Erik
Erik

Reputation: 91270

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.

Upvotes: 6

Related Questions