c - How to print a single character from an array of strings using printf? -
let's have
char *names[] = { "tom", "jerry" };
and want print "e" in "jerry" using printf
. first instinct was
printf("%c\n", *names[5]);
but when applied i've been learning pointers, realized total junk code because 5 refers nonexistent 5th pointer in names
, not "e" in "jerry". pointers contained in names
ever refer memory addresses of first characters in respective strings.
so seems need add together 1 byte names[1]
point to, , print "e" in "jerry". i'm not sure how this, or whether it's allowed in c.
what best way accomplish this? give thanks in advance.
i think you're looking printf("%c\n", names[1][1]);
.
c arrays pointers
No comments:
Post a Comment