How to print a single character from an array of strings using printf?

intelli78

Let's say I have

char *names[] = { "Tom", "Jerry" };

and I want to print the "e" in "Jerry" using printf. My first instinct was

printf("%c\n", *names[5]);

but when I applied what I've been learning about pointers, I realized this is total junk code because the 5 refers to the nonexistent fifth pointer in names, not the "e" in "Jerry". The pointers contained in names will only ever refer to the memory addresses of the first characters in their respective strings.

So it seems what I really need to do is to add one byte to names[1] to point to, and print the "e" in "Jerry". But I'm not sure how to do this, or whether it's even allowed in C.

What is the best way to accomplish this? Thank you in advance.

Fred Larson

I think what you're looking for is printf("%c\n", names[1][1]);.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to print the "%" character with printf?

From Dev

How to print the "%" character with printf?

From Dev

Bash - How to print multi line strings (with '\n') using printf

From Dev

How to use printf to print a character multiple times?

From Dev

How to use printf to print a character multiple times?

From Dev

how to print 5 unique strings from array of 10 strings

From Dev

How to print a single-precision float with printf

From Dev

How to convert from printf to print?

From Dev

Print from array of strings in C

From Dev

printw() won't print a single character from a uint8_t array

From Dev

How to print a single column from a jagged char array

From Dev

How to print single field data from json array

From Dev

How can I print multiple character with one printf?

From Dev

Using `printf` to print variable containing `%` percent sign results in "bash: printf: `p': invalid format character"

From Dev

Can printf print defined strings?

From Dev

How to print an array single elements of an array in a table?

From Dev

How to print a char array and a certain character in it?

From Dev

printf adds extra `FFFFFF` to hex print from a char array

From Dev

Iterate through List of single character strings using indexOf()

From Dev

How to print a random character from a string?

From Dev

How to retrieve & print values from array using Twig?

From Dev

How to print elements from generic array list, using iterator in Java

From Dev

How to print sorted lines from file using array of structures in C

From Dev

How to copy from character array to character pointer?

From Dev

How to break a single string into an array of strings?

From Dev

How to break a single string into an array of strings?

From Dev

How to store stemmed strings into single array?

From Dev

How to get a single Unicode character from string

From Dev

NASM - printf doesn't print the first character

Related Related

  1. 1

    How to print the "%" character with printf?

  2. 2

    How to print the "%" character with printf?

  3. 3

    Bash - How to print multi line strings (with '\n') using printf

  4. 4

    How to use printf to print a character multiple times?

  5. 5

    How to use printf to print a character multiple times?

  6. 6

    how to print 5 unique strings from array of 10 strings

  7. 7

    How to print a single-precision float with printf

  8. 8

    How to convert from printf to print?

  9. 9

    Print from array of strings in C

  10. 10

    printw() won't print a single character from a uint8_t array

  11. 11

    How to print a single column from a jagged char array

  12. 12

    How to print single field data from json array

  13. 13

    How can I print multiple character with one printf?

  14. 14

    Using `printf` to print variable containing `%` percent sign results in "bash: printf: `p': invalid format character"

  15. 15

    Can printf print defined strings?

  16. 16

    How to print an array single elements of an array in a table?

  17. 17

    How to print a char array and a certain character in it?

  18. 18

    printf adds extra `FFFFFF` to hex print from a char array

  19. 19

    Iterate through List of single character strings using indexOf()

  20. 20

    How to print a random character from a string?

  21. 21

    How to retrieve & print values from array using Twig?

  22. 22

    How to print elements from generic array list, using iterator in Java

  23. 23

    How to print sorted lines from file using array of structures in C

  24. 24

    How to copy from character array to character pointer?

  25. 25

    How to break a single string into an array of strings?

  26. 26

    How to break a single string into an array of strings?

  27. 27

    How to store stemmed strings into single array?

  28. 28

    How to get a single Unicode character from string

  29. 29

    NASM - printf doesn't print the first character

HotTag

Archive