CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: sprintf_s error

  1. #1
    Join Date
    Nov 2008
    Posts
    17

    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

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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?

  3. #3
    Join Date
    Nov 2008
    Posts
    17

    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
  •  





Click Here to Expand Forum to Full Width

Featured