Click here to Skip to main content
15,798,729 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C: Book recommendations Pin
Albert Holguin6-Oct-15 5:59
professionalAlbert Holguin6-Oct-15 5:59 
QuestionWindows message for changing color scheme Pin
_Flaviu5-Oct-15 3:15
_Flaviu5-Oct-15 3:15 
AnswerRe: Windows message for changing color scheme Pin
_Flaviu5-Oct-15 4:07
_Flaviu5-Oct-15 4:07 
QuestionRe: Windows message for changing color scheme Pin
Richard MacCutchan5-Oct-15 4:47
mveRichard MacCutchan5-Oct-15 4:47 
AnswerRe: Windows message for changing color scheme Pin
_Flaviu5-Oct-15 21:18
_Flaviu5-Oct-15 21:18 
AnswerRe: Windows message for changing color scheme Pin
_Flaviu7-Oct-15 1:46
_Flaviu7-Oct-15 1:46 
Questionuploadig adobe reader file in local host in c language Pin
sunycity4-Oct-15 23:31
sunycity4-Oct-15 23:31 
AnswerRe: uploadig adobe reader file in local host in c language Pin
Jochen Arndt4-Oct-15 23:54
professionalJochen Arndt4-Oct-15 23:54 
You should not pass the buffer itself as format argument to sprintf. It depends on the implementation (the used standard C library) if it is supported or not. But even if it is supported it is bad style. And in your case it is the reason for the corrupted buffer content here:
C++
sprintf(buffer, "%s\r\n", buffer);
memcpy(buffer + strlen(buffer),content,lSize);
sprintf(buffer, "%s\r\n", buffer);

The PDF file is a binary file. While you use memcpy to append the binary data to your buffer, the next sprintf call stops at the first null byte truncating the buffer.

A common solution is to use a buffer offset variable which is incremented by the return value of sprintf:
C++
int ofs = strlen(buffer);
ofs += sprintf(buffer + ofs, "\r\n");
memcpy(buffer + ofs,content,lSize);
ofs += lSize;
ofs += sprintf(buffer + ofs, "\r\n");

QuestionCFileDialog OnTypeChange issue Pin
_Flaviu1-Oct-15 21:59
_Flaviu1-Oct-15 21:59 
QuestionRe: CFileDialog OnTypeChange issue Pin
_Flaviu2-Oct-15 4:00
_Flaviu2-Oct-15 4:00 
AnswerRe: CFileDialog OnTypeChange issue Pin
Maximilien2-Oct-15 5:06
Maximilien2-Oct-15 5:06 
GeneralRe: CFileDialog OnTypeChange issue Pin
_Flaviu4-Oct-15 22:29
_Flaviu4-Oct-15 22:29 
QuestionA c program to project expected number of rabbits on a farm Pin
Arnold Mukisa29-Sep-15 9:27
Arnold Mukisa29-Sep-15 9:27 
AnswerRe: A c program to project expected number of rabbits on a farm Pin
Arnold Mukisa29-Sep-15 9:30
Arnold Mukisa29-Sep-15 9:30 
SuggestionRe: A c program to project expected number of rabbits on a farm Pin
David Crow29-Sep-15 16:42
David Crow29-Sep-15 16:42 
GeneralRe: A c program to project expected number of rabbits on a farm Pin
David Crow29-Sep-15 16:34
David Crow29-Sep-15 16:34 
QuestionRe: A c program to project expected number of rabbits on a farm Pin
Paul Conrad1-Oct-15 8:33
professionalPaul Conrad1-Oct-15 8:33 
GeneralRe: A c program to project expected number of rabbits on a farm Pin
David Crow1-Oct-15 11:19
David Crow1-Oct-15 11:19 
Question0 bytes CImage saved Pin
_Flaviu29-Sep-15 0:47
_Flaviu29-Sep-15 0:47 
QuestionRe: 0 bytes CImage saved Pin
CPallini29-Sep-15 1:02
mveCPallini29-Sep-15 1:02 
AnswerRe: 0 bytes CImage saved Pin
_Flaviu29-Sep-15 1:06
_Flaviu29-Sep-15 1:06 
AnswerRe: 0 bytes CImage saved Pin
_Flaviu29-Sep-15 1:33
_Flaviu29-Sep-15 1:33 
SuggestionRe: 0 bytes CImage saved Pin
Jochen Arndt29-Sep-15 1:36
professionalJochen Arndt29-Sep-15 1:36 
GeneralRe: 0 bytes CImage saved Pin
_Flaviu29-Sep-15 1:57
_Flaviu29-Sep-15 1:57 
GeneralRe: 0 bytes CImage saved Pin
Jochen Arndt29-Sep-15 1:59
professionalJochen Arndt29-Sep-15 1:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.