Click here to Skip to main content
15,501,351 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Comparing Files for Differences Pin
jeron127-Sep-17 5:09
Memberjeron127-Sep-17 5:09 
QuestionRe: Comparing Files for Differences Pin
David Crow27-Sep-17 6:24
MemberDavid Crow27-Sep-17 6:24 
AnswerRe: Comparing Files for Differences Pin
jschell27-Sep-17 10:23
Memberjschell27-Sep-17 10:23 
GeneralRe: Comparing Files for Differences Pin
Member 1343302228-Sep-17 3:41
MemberMember 1343302228-Sep-17 3:41 
GeneralRe: Comparing Files for Differences Pin
Jochen Arndt28-Sep-17 4:29
professionalJochen Arndt28-Sep-17 4:29 
GeneralMessage Closed Pin
29-Sep-17 5:00
MemberMember 1343302229-Sep-17 5:00 
GeneralRe: Comparing Files for Differences Pin
jeron129-Sep-17 5:47
Memberjeron129-Sep-17 5:47 
GeneralRe: Comparing Files for Differences Pin
Jochen Arndt29-Sep-17 5:58
professionalJochen Arndt29-Sep-17 5:58 
I would use the C standard library functions fopen, fread (full file), fgets (read line), strchr (find NL), and strncmp (find match).

A quick try from scratch without error checking (therefore untested):
C++
// Maybe not all required header are shown here
#include <stdio.h>
#include <sys/stat.h>

// Get file size, allocate buffer, and read file 2 into memory
struct stat st;
stat(file2, &st);
char *buf = new char[st.st_size + 1];
FILE *f2 = fopen(file2, "rb");
fread(buf, 1, st.st_size, f2);
fclose(f2);
buf[st.st_size] = 0;

// Count lines
unsigned lines = 0;
char *p = buf;
while (NULL != (p = strchr(p, '\n')))
{
    p++;
    lines++;
}

// Get line pointers
char **lineptr = new char* [lines+1];
p = buf;
unsigned i = 0;
lineptr[0] = buf;
while (NULL != (p = strchr(p, '\n')))
{
    lineptr[++i] = ++p;
}

// Must be large enough to hold max. line length
char linebuf[1024];
FILE *f1 = fopen(file1, "rb");
FILE *f3 = fopen(file3, "wb");
do
{
    if (NULL == fgets(linebuf, sizeof(linebuf), f1))
        break;
    if (0 == linebuf[0])
        break;
    // Ignore empty lines
    if ('\r' == linebuf[0] || '\n' == linebuf[0])
        continue;
    for (i = 0; i < lines; i++)
    {
        if (0 == strncmp(linebuf, lineptr[i], strlen(linebuf)))
            break;
    }
    if (i >= lines)
        fputs(linebuf, f3);
}
while (!feof(f1));
fclose(f3);
fclose(f1);
delete [] lineptr;
delete [] buf;

GeneralRe: Comparing Files for Differences Pin
jschell29-Sep-17 7:57
Memberjschell29-Sep-17 7:57 
AnswerRe: Comparing Files for Differences Pin
Joe Woodbury29-Sep-17 14:04
professionalJoe Woodbury29-Sep-17 14:04 
AnswerRe: Comparing Files for Differences Pin
User 5838523-Oct-17 8:28
MemberUser 5838523-Oct-17 8:28 
Questionsend notification to srvice Pin
john563227-Sep-17 0:05
Memberjohn563227-Sep-17 0:05 
AnswerRe: send notification to srvice Pin
CPallini27-Sep-17 0:25
mveCPallini27-Sep-17 0:25 
QuestionTo create drag and drop graphics builder Pin
manoharbalu25-Sep-17 22:05
Membermanoharbalu25-Sep-17 22:05 
AnswerRe: To create drag and drop graphics builder Pin
Richard MacCutchan25-Sep-17 22:19
mveRichard MacCutchan25-Sep-17 22:19 
GeneralRe: To create drag and drop graphics builder Pin
manoharbalu25-Sep-17 23:26
Membermanoharbalu25-Sep-17 23:26 
GeneralRe: To create drag and drop graphics builder Pin
Richard MacCutchan25-Sep-17 23:30
mveRichard MacCutchan25-Sep-17 23:30 
QuestionHelp with no default constructor message Pin
ForNow23-Sep-17 20:03
MemberForNow23-Sep-17 20:03 
AnswerRe: Help with no default constructor message Pin
Richard MacCutchan23-Sep-17 22:06
mveRichard MacCutchan23-Sep-17 22:06 
GeneralRe: Help with no default constructor message Pin
ForNow24-Sep-17 4:52
MemberForNow24-Sep-17 4:52 
GeneralRe: Help with no default constructor message Pin
Richard MacCutchan24-Sep-17 5:00
mveRichard MacCutchan24-Sep-17 5:00 
GeneralRe: Help with no default constructor message Pin
ForNow24-Sep-17 5:12
MemberForNow24-Sep-17 5:12 
GeneralRe: Help with no default constructor message Pin
ForNow24-Sep-17 7:02
MemberForNow24-Sep-17 7:02 
AnswerRe: Help with no default constructor message Pin
Richard Andrew x6424-Sep-17 6:40
professionalRichard Andrew x6424-Sep-17 6:40 
GeneralRe: Help with no default constructor message Pin
ForNow24-Sep-17 6:57
MemberForNow24-Sep-17 6:57 

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.