Hii All,
i am a begginer at c programming in the first semetser of study, and i am trying to doing my project what is:

Diff — The program should compare two text files and list the differences, i.e. lines and columns of the beginning and the end of a given difference.

i dont know how to start or what to do with this, please anyhelp :)
thank you

Recommended Answers

All 10 Replies

Programming is thinking.

How would you do this on paper? If I gave you two sheets of paper with writing on, and asked you to find the first difference, how would you do that?

of course i will read both of papers, and obviuosly i will know the diffrence where it is.
i have the source code, i already tried to write one in visaul basic, but i dont know how do i know that the program will function, otherwise how to creat the program.

Are you saying you don't know how to create a C program?

yes exactly! coz at the classes we just took how to create array, strings, and the basic stuffs

i know this, but what to do with it, this is my problem brother :(

I am also a C beginner , but I think this should help
1. you need to code to Count the number of Words and Character in the file....
2. Each file will be deal with and their value will be store...
3. Compare the Result and Display it or use it in anyway you will like to use it.....I have a simple similar code, but this only take user input from the terminal not file....

of course i will read both of papers, and obviuosly i will know the diffrence where it is.

That's not enough to write a program. You need to break down things such that a stupid literal child (aka. a computer) could go through the steps and accomplish the goal.

For example, how would you read both papers? What things would you look at, in what order, how would those things be meaningful for comparing differences? Nothing is obvious to a computer, so even though you would intuitively see a difference, you need to define in exacting detail what a difference looks like with given data and how to interpret it in a systematic way without using any intuition or complex jumping around. This is the purpose of a paper run: to define explicit steps and weed out implicit assumptions.

Hiii Guys thank you for your advice, any was really helpful for me.
i spent all night writing the code so i hope it useful, i would like that somebody tell me where is my mistakes. here i had written just code to compare text files line by line, how can i show the diffrence then. and after i finish the code how can i creat the program, i am using visual studio 2013. i really would like that you help me guys coz i should give my project up that night. thank you in advance :)

int comp_line(FILE *fp1, FILE *fp2){
char l1[1024];
char l2[1024];
char w1[1024];
char w2[1024];
char *c1;
char *c2;

/*initialize*/
c1 = fgets(l1,1024,fp1);
c2 = fgets(l2,1024,fp2);

sscanf(w1,"%1023s",l1);
sscanf(w2,"%1023s",l2);

while (c1 != NULL && c2 != NULL && strcmp(w1,w2) == 0)
{   
    c1 = fgets(l1,1024,fp1);
    c2 = fgets(l2,1024,fp2);
    sscanf(w1,"%1023s",l1);
    sscanf(w1,"%1023s",l1);
    if(c1 != NULL && c2 == NULL)
    {
        printf("EOF 2");
        return 0;
    }
    if(c1 == NULL && c2 != NULL)
    {
        printf("EOF 1");
        return 0;
    }

}
if(strcmp(w1,w2) == 0)
{
    printf("\nfiles are equal");
    return 0;
}
else
{
    printf("\nfiles different");
    return 1;
}
return 0;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.