-
September 1st, 2009, 03:30 PM
#1
sprintf_s error
Hi,
I'm trying to display a string on a message box.
unsigned char buffer[64];
char display[100]
fread(buffer, 1, 64, fp);
sprintf_s(display, 65, "%s", buffer);
AfxMessageBox((LPCTSTR)display);
I get an error saying "buffer too small". I don't understand this error because I'm storing 65 bytes in a 100 byte array.
--- Richard Dinoso
-
September 1st, 2009, 03:34 PM
#2
Re: sprintf_s error
The array may be 100 bytes, but you've informed the function that it's only 65 bytes.
Which still ought to be big enough if the data that you got from fread() was properly NULL-terminated. Is it?
-
September 1st, 2009, 03:41 PM
#3
Re: sprintf_s error
Oh I see. I thought the 65 tells the function to only copy that much from the source. I need to NULL terminate my source. Thanks.
--- Richard Dinoso
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|