Click here to Skip to main content
14,487,920 members

C / C++ / MFC

 
GeneralRe: file not recognized: File format not recognized Pin
Vaclav_29-Jan-20 6:58
MemberVaclav_29-Jan-20 6:58 
GeneralRe: file not recognized: File format not recognized Pin
k505429-Jan-20 7:15
Memberk505429-Jan-20 7:15 
GeneralRe: file not recognized: File format not recognized Pin
Vaclav_29-Jan-20 15:39
MemberVaclav_29-Jan-20 15:39 
Questionreplace words in a file Pin
Member 1295754729-Jan-20 4:19
MemberMember 1295754729-Jan-20 4:19 
AnswerRe: replace words in a file Pin
Victor Nijegorodov29-Jan-20 5:30
MemberVictor Nijegorodov29-Jan-20 5:30 
GeneralRe: replace words in a file Pin
Member 1295754729-Jan-20 5:34
MemberMember 1295754729-Jan-20 5:34 
GeneralRe: replace words in a file Pin
k505429-Jan-20 5:52
Memberk505429-Jan-20 5:52 
AnswerRe: replace words in a file Pin
k505429-Jan-20 5:42
Memberk505429-Jan-20 5:42 
Haven't tried to run your code, but I do notice a couple things:

1: you call fopen() several times, but there's no corresponding fclose(). If you had a large file (say the text of the bible), and wanted to replace, "god" with "jimmy", you would probably run out of file handles before completing the task.

2: you continually call fopen on the same file. fopen("file1.txt", "w") truncates the file, so some future read may return EOF unexpectedly. [NB not necessarily the next read, as the call to fgets might fill an input buffer, which following calls use, rather than continually reading from the file] My suggestion would be to open a temporary file and write your output there, then copy or replace the input file with the temp file. tmpfile() might be useful, here.

3: fgets() reads up to size-1 bytes from the input stream. What happens if you have very long lines (over 999 chars, in your case), and the word you want occupies chars 996-1003? You'll get the first 3 chars in one read and the remaining 4 in the next, missing an occurrence. Might I suggest you look at getline().

4: do you need to concern yourself with word case? Do you need to replace "babble" with "brook", "Babble" with "Brook" and "BABBLE" with "BROOK"?
SuggestionRe: replace words in a file Pin
David Crow29-Jan-20 17:04
MemberDavid Crow29-Jan-20 17:04 
AnswerRe: replace words in a file Pin
Stefan_Lang29-Jan-20 21:21
mveStefan_Lang29-Jan-20 21:21 
QuestionLinking libraries - follow-up- gcc++ won't link Pin
Vaclav_28-Jan-20 4:22
MemberVaclav_28-Jan-20 4:22 
AnswerRe: Linking libraries - follow-up- gcc++ won't link Pin
Richard MacCutchan28-Jan-20 5:04
mveRichard MacCutchan28-Jan-20 5:04 
AnswerRe: Linking libraries - follow-up- gcc++ won't link Pin
k505428-Jan-20 5:08
Memberk505428-Jan-20 5:08 
AnswerRe: Linking libraries - follow-up- gcc++ won't link Pin
CPallini28-Jan-20 5:13
mveCPallini28-Jan-20 5:13 
GeneralRe: Linking libraries - follow-up- gcc++ won't link Pin
k505428-Jan-20 6:47
Memberk505428-Jan-20 6:47 
GeneralRe: Linking libraries - follow-up- gcc++ won't link Pin
CPallini28-Jan-20 9:52
mveCPallini28-Jan-20 9:52 
AnswerRe: Linking libraries - follow-up- gcc++ won't link Pin
Vaclav_28-Jan-20 7:07
MemberVaclav_28-Jan-20 7:07 
GeneralRe: Linking libraries - follow-up- gcc++ won't link Pin
Richard MacCutchan28-Jan-20 9:22
mveRichard MacCutchan28-Jan-20 9:22 
AnswerSOLVED (?) Re: Linking libraries - follow-up- gcc++ won't link Pin
Vaclav_29-Jan-20 4:00
MemberVaclav_29-Jan-20 4:00 
GeneralRe: SOLVED (?) Re: Linking libraries - follow-up- gcc++ won't link Pin
Richard MacCutchan29-Jan-20 4:16
mveRichard MacCutchan29-Jan-20 4:16 
QuestionReverse engineering GCC output - need library file (name) and path. Pin
Vaclav_27-Jan-20 5:34
MemberVaclav_27-Jan-20 5:34 
AnswerRe: Reverse engineering GCC output - need library file (name) and path. Pin
Gerry Schmitz27-Jan-20 5:55
mveGerry Schmitz27-Jan-20 5:55 
GeneralRe: Reverse engineering GCC output - need library file (name) and path. Pin
Vaclav_28-Jan-20 2:44
MemberVaclav_28-Jan-20 2:44 
AnswerRe: Reverse engineering GCC output - need library file (name) and path. Pin
Richard MacCutchan27-Jan-20 6:09
mveRichard MacCutchan27-Jan-20 6:09 
AnswerRe: Reverse engineering GCC output - need library file (name) and path. Pin
k505427-Jan-20 6:24
Memberk505427-Jan-20 6:24 

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.