C++: How do I dereference multiple characters from a character pointer in memory using the namelength
Here is the code:
errorLog.OutputSuccess("Filename reference: %c", *t_current_node->filename);
It of course only outputs the first character. If I add something like ->filename[nameLen]
where nameLen is a valid integer of say 10 it says:
operand of * must be a pointer.
Thanks!
If the string is terminated with \0
, you could use %s
instead:
errorLog.OutputSuccess("Filename reference: %s", t_current_node->filename);
You also will need to pass the memory address of filename, so lose the *
symbol.
Use %s, and remove the *
errorLog.OutputSuccess("Filename reference: %s", t_current_node->filename);
%c
prints a single character.%s
prints a string: all characters up to the terminating\0
.%.10s
prints the first 10 characters of a string (or less, if the string is shorter)%.*s
takes two arguments, an integer indicating the length to print, and a string pointer.
Example for the last case:
printf("Filename reference: %.*s", nameLen, t_current_node->filename);
精彩评论