How do you print a limited number of characters?
Posted
by Mike Pateras
on Stack Overflow
See other posts from Stack Overflow
or by Mike Pateras
Published on 2010-04-15T00:13:39Z
Indexed on
2010/04/15
0:23 UTC
Read the original article
Hit count: 287
Sorry to put a post up about something so simple, but I don't see what I'm doing wrong here.
char data[1024];
DWORD numRead;
ReadFile(handle, data, 1024, &numRead, NULL);
if (numRead > 0)
printf(data, "%.5s");
My intention with the above is to read data from a file, and then only print out 5 characters. However, it prints out all 1024 characters, which is contrary to what I'm reading here. The goal, of course, is to do something like:
printf(data, "%.*s", numRead);
What am I doing wrong here?
© Stack Overflow or respective owner