Click here to Skip to main content
15,796,456 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder12-Jul-09 23:37
cofounderChris Maunder12-Jul-09 23:37 
PinnedHOW TO ASK A QUESTION PinPopular
Chris Maunder12-Feb-09 18:19
cofounderChris Maunder12-Feb-09 18:19 
Questiondownload a web page Pin
mike741117hrs 35mins ago
mike741117hrs 35mins ago 
AnswerRe: download a web page Pin
Mircea Neacsu17hrs 5mins ago
Mircea Neacsu17hrs 5mins ago 
GeneralRe: download a web page Pin
mike74118hrs 37mins ago
mike74118hrs 37mins ago 
GeneralRe: download a web page Pin
Mircea Neacsu7hrs 47mins ago
Mircea Neacsu7hrs 47mins ago 
AnswerRe: download a web page Pin
jschell15hrs 13mins ago
jschell15hrs 13mins ago 
AnswerRe: download a web page Pin
Gerry Schmitz14hrs 37mins ago
mveGerry Schmitz14hrs 37mins ago 
Questioncopying a file in C++17 Pin
mike74115-Dec-23 22:36
mike74115-Dec-23 22:36 
AnswerRe: copying a file in C++17 Pin
Richard MacCutchan23hrs 58mins ago
mveRichard MacCutchan23hrs 58mins ago 
AnswerRe: copying a file in C++17 Pin
jschell15hrs 1 min ago
jschell15hrs 1 min ago 
Questionprintf without stdio.h Pin
mike74115-Dec-23 6:21
mike74115-Dec-23 6:21 
AnswerRe: printf without stdio.h Pin
Mircea Neacsu5-Dec-23 6:31
Mircea Neacsu5-Dec-23 6:31 
GeneralRe: printf without stdio.h Pin
mike74115-Dec-23 17:23
mike74115-Dec-23 17:23 
GeneralRe: printf without stdio.h Pin
Mircea Neacsu5-Dec-23 17:42
Mircea Neacsu5-Dec-23 17:42 
AnswerRe: printf without stdio.h Pin
Victor Nijegorodov5-Dec-23 6:32
Victor Nijegorodov5-Dec-23 6:32 
AnswerRe: printf without stdio.h Pin
k50545-Dec-23 7:02
mvek50545-Dec-23 7:02 
GeneralRe: printf without stdio.h Pin
jschell14hrs 58mins ago
jschell14hrs 58mins ago 
Questioncopying a file Pin
mike74115-Dec-23 4:24
mike74115-Dec-23 4:24 
AnswerRe: copying a file Pin
Mircea Neacsu5-Dec-23 4:32
Mircea Neacsu5-Dec-23 4:32 
AnswerRe: copying a file Pin
Richard MacCutchan5-Dec-23 5:05
mveRichard MacCutchan5-Dec-23 5:05 
AnswerRe: copying a file Pin
k50545-Dec-23 5:42
mvek50545-Dec-23 5:42 
While your method may work, assuming that ch is an int, and so does not have the 255/-1 issue, your method is horribly inefficient. Richard's suggestion to use fread/fwrite produces much better performance.

For example, given an 8M file, looping through your code 100 times took about 32 seconds. Using a fread/fwrite using a 4K buffer, the same 100 lops took just under 1 second to complete. This was on a PI-3, and successive runs remained stable. I'd expect an 8M file to sit comfortably in the file cache, so the difference is totally down to the difference between extracting a single char at a time, and reading a lot of characters at a time.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown

QuestionMyth of a Myth? Pin
jschell4-Dec-23 4:38
jschell4-Dec-23 4:38 
AnswerRe: Myth of a Myth? Pin
Richard MacCutchan4-Dec-23 5:57
mveRichard MacCutchan4-Dec-23 5:57 
AnswerRe: Myth of a Myth? Pin
Mircea Neacsu4-Dec-23 6:05
Mircea Neacsu4-Dec-23 6:05 

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.