Click here to Skip to main content
15,889,335 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Reference return vs Pointer return Pin
Aragtey24-Apr-12 5:37
Aragtey24-Apr-12 5:37 
GeneralRe: Reference return vs Pointer return Pin
Aescleal24-Apr-12 6:31
Aescleal24-Apr-12 6:31 
GeneralRe: Reference return vs Pointer return Pin
Aragtey24-Apr-12 6:36
Aragtey24-Apr-12 6:36 
GeneralRe: Reference return vs Pointer return Pin
Aescleal25-Apr-12 5:19
Aescleal25-Apr-12 5:19 
QuestionBest approach to compare files Pin
MKC00223-Apr-12 23:37
MKC00223-Apr-12 23:37 
AnswerRe: Best approach to compare files Pin
sangamdumne23-Apr-12 23:49
sangamdumne23-Apr-12 23:49 
GeneralRe: Best approach to compare files Pin
MKC00224-Apr-12 0:22
MKC00224-Apr-12 0:22 
GeneralRe: Best approach to compare files Pin
enhzflep24-Apr-12 1:35
enhzflep24-Apr-12 1:35 
It really depends on what kind a value you wish to return from the function.

For instance I can envisage two basic approaches - true/false for same/not same, or a -/0/+ value as strcmp does.

Here's an approach that just returns true/false.
I've timed it - it takes 6 seconds to compare a 347MB video file with itself - Win7 Home Premium x64, Intel i3 @ 2.13Ghz, 4GB ram - gcc 4.4.1


C++
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void loadFile(char *szFilename, size_t &sizeOut, char* &bufferOut)
{
    FILE *fp;

    fp = fopen(szFilename, "rb");
    fseek(fp, 0, SEEK_END);
    sizeOut = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    bufferOut = (char*) malloc(sizeOut);
    fread(bufferOut, 1, sizeOut, fp);
    fclose(fp);
}

bool isSame(char *szFilename1, char *szFilename2)
{
    size_t len1, len2;
    long curPos;
    char *buffer1, *buffer2;
    bool result = true;

    loadFile(szFilename1, len1, buffer1);
    loadFile(szFilename2, len2, buffer2);

    if (len1 == len2)
    {
        for (curPos=0; curPos<len1; curPos++)
        {
            if (buffer1[curPos] != buffer2[curPos])
                result = false;
        }
    }

    else
        result = false;

    free(buffer1);
    free(buffer2);
    return result;
}


int main()
{
    if (isSame("testVideo.avi", "testVideo.avi"))
        printf("Same\n");
    else
        printf("Not Same\n");
}

AnswerRe: Best approach to compare files Pin
Chris Losinger24-Apr-12 1:46
professionalChris Losinger24-Apr-12 1:46 
QuestionRe: Best approach to compare files Pin
Randor 24-Apr-12 20:35
professional Randor 24-Apr-12 20:35 
AnswerRe: Best approach to compare files Pin
Chris Losinger25-Apr-12 1:31
professionalChris Losinger25-Apr-12 1:31 
QuestionCreate And Start Service using C++ Pin
sangamdumne23-Apr-12 23:36
sangamdumne23-Apr-12 23:36 
AnswerRe: Create And Start Service using C++ Pin
JohnCz24-Apr-12 2:59
JohnCz24-Apr-12 2:59 
GeneralRe: Create And Start Service using C++ Pin
sangamdumne24-Apr-12 22:57
sangamdumne24-Apr-12 22:57 
GeneralRe: Create And Start Service using C++ Pin
JohnCz24-Apr-12 23:33
JohnCz24-Apr-12 23:33 
GeneralRe: Create And Start Service using C++ Pin
sangamdumne25-Apr-12 20:19
sangamdumne25-Apr-12 20:19 
QuestionIndata validation char* input Pin
Johan Bertilsdotter23-Apr-12 22:21
Johan Bertilsdotter23-Apr-12 22:21 
QuestionRe: Indata validation char* input Pin
CPallini24-Apr-12 0:58
mveCPallini24-Apr-12 0:58 
QuestionIncorrect output of sum Pin
Ron120223-Apr-12 21:28
Ron120223-Apr-12 21:28 
Question[SOLVED] Loading Bitmap Into Picture Control Pin
AmbiguousName23-Apr-12 18:57
AmbiguousName23-Apr-12 18:57 
AnswerRe: Loading Bitmap Into Picture Control Pin
enhzflep23-Apr-12 22:49
enhzflep23-Apr-12 22:49 
AnswerRe: Loading Bitmap Into Picture Control Pin
AmbiguousName23-Apr-12 23:28
AmbiguousName23-Apr-12 23:28 
AnswerRe: Loading Bitmap Into Picture Control Pin
SandipG 23-Apr-12 22:51
SandipG 23-Apr-12 22:51 
AnswerRe: Loading Bitmap Into Picture Control Pin
AmbiguousName23-Apr-12 23:31
AmbiguousName23-Apr-12 23:31 
GeneralRe: Loading Bitmap Into Picture Control Pin
enhzflep24-Apr-12 0:54
enhzflep24-Apr-12 0:54 

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.