Click here to Skip to main content
15,885,782 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Comparing Files for Differences Pin
jeron127-Sep-17 4:09
jeron127-Sep-17 4:09 
QuestionRe: Comparing Files for Differences Pin
David Crow27-Sep-17 5:24
David Crow27-Sep-17 5:24 
AnswerRe: Comparing Files for Differences Pin
jschell27-Sep-17 9:23
jschell27-Sep-17 9:23 
GeneralRe: Comparing Files for Differences Pin
Member 1343302228-Sep-17 2:41
Member 1343302228-Sep-17 2:41 
GeneralRe: Comparing Files for Differences Pin
Jochen Arndt28-Sep-17 3:29
professionalJochen Arndt28-Sep-17 3:29 
GeneralMessage Closed Pin
29-Sep-17 4:00
Member 1343302229-Sep-17 4:00 
GeneralRe: Comparing Files for Differences Pin
jeron129-Sep-17 4:47
jeron129-Sep-17 4:47 
GeneralRe: Comparing Files for Differences Pin
Jochen Arndt29-Sep-17 4:58
professionalJochen Arndt29-Sep-17 4: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 6:57
jschell29-Sep-17 6:57 
AnswerRe: Comparing Files for Differences Pin
Joe Woodbury29-Sep-17 13:04
professionalJoe Woodbury29-Sep-17 13:04 
AnswerRe: Comparing Files for Differences Pin
User 5838523-Oct-17 7:28
User 5838523-Oct-17 7:28 
Questionsend notification to srvice Pin
john563226-Sep-17 23:05
john563226-Sep-17 23:05 
AnswerRe: send notification to srvice Pin
CPallini26-Sep-17 23:25
mveCPallini26-Sep-17 23:25 
QuestionTo create drag and drop graphics builder Pin
manoharbalu25-Sep-17 21:05
manoharbalu25-Sep-17 21:05 
AnswerRe: To create drag and drop graphics builder Pin
Richard MacCutchan25-Sep-17 21:19
mveRichard MacCutchan25-Sep-17 21:19 
GeneralRe: To create drag and drop graphics builder Pin
manoharbalu25-Sep-17 22:26
manoharbalu25-Sep-17 22:26 
GeneralRe: To create drag and drop graphics builder Pin
Richard MacCutchan25-Sep-17 22:30
mveRichard MacCutchan25-Sep-17 22:30 
QuestionHelp with no default constructor message Pin
ForNow23-Sep-17 19:03
ForNow23-Sep-17 19:03 
AnswerRe: Help with no default constructor message Pin
Richard MacCutchan23-Sep-17 21:06
mveRichard MacCutchan23-Sep-17 21:06 
GeneralRe: Help with no default constructor message Pin
ForNow24-Sep-17 3:52
ForNow24-Sep-17 3:52 
GeneralRe: Help with no default constructor message Pin
Richard MacCutchan24-Sep-17 4:00
mveRichard MacCutchan24-Sep-17 4:00 
GeneralRe: Help with no default constructor message Pin
ForNow24-Sep-17 4:12
ForNow24-Sep-17 4:12 
GeneralRe: Help with no default constructor message Pin
ForNow24-Sep-17 6:02
ForNow24-Sep-17 6:02 
AnswerRe: Help with no default constructor message Pin
Richard Andrew x6424-Sep-17 5:40
professionalRichard Andrew x6424-Sep-17 5:40 
GeneralRe: Help with no default constructor message Pin
ForNow24-Sep-17 5:57
ForNow24-Sep-17 5: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.