Click here to Skip to main content
15,921,452 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I got two code file.I wanna compare two text file and I wanna show difference in text.that will do linked list.Firstly,I integrated the text with linked list.I chose the boyer moore algorithm to compare string.But I don't know merge two code file.I sent the codes.thank you very much for helping. :)

for linked list
C++
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<locale.h>

struct List
{
       char *val;
       struct List *next;
      
       };
       typedef struct List Node;
      
       Node *curr,*head;
      
       void ekle(char *deger)
       {
            
            curr->val = deger;
           
            Node *tmp = (Node*)malloc(sizeof(Node));
           
            tmp->next = NULL;
            
            curr->next = tmp;
            
            printf("%s",curr->val);printf(" ");
        
            curr = curr -> next;
            }
            
            void satiriAyir(char *satir)
            {
                 char *kelime = NULL;
                 kelime = strtok (satir," ");
                 while(kelime !=NULL)
                 {
                              ekle(kelime);
                              kelime = strtok (NULL, " ");
                              }
                              }
                              
                              int main()
                              {
                                  setlocale(LC_ALL,"Turkish");
                                
                                  curr = (Node *)malloc(sizeof(Node));
                                  curr ->next=NULL;
                                  head = curr;
                                  FILE *fp = fopen("C:\\Users\\orçun\\Desktop\\metin1.txt","r");
                                  char satir[1000];
                                  while (fgets( satir,sizeof(satir),fp ))
                                  satiriAyir(satir);
                                  fclose(fp);
                                  getch();
                                  return 0;
                                  }

and for boyer moore algorithm:
C#
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
#include<process.h>
#include<stdlib.h>


int main()
{
    char string[1000], substring[1000];
    int strvalue[256], i, j, diff = 0, count = 0;

    printf("Input string: ");
    gets(string);
    printf("Input substring: ");
    gets(substring);
    for (i = 0; i < 256; i++)
    {
        strvalue[i] = -1;
    }
    for (i = strlen(substring) - 1; i >= 0 ; i--)
    {
        if (strvalue[substring[i]] == -1)
            strvalue[substring[i]] = i;
    }
    for (i = 0; i < 256; i++)
    {
        if (strvalue[substring[i]] == -1)
            strvalue[substring[i]] = strlen(substring);
    }
    i = strlen(substring) - 1;
    while (true)
    {
        for (j = strlen(substring) - 1; j >= 0 ; j--)
        {
            if (substring[j] == string[i - diff])
            {
                count++;
                diff++;
            }
            else
                break;
            if (count == strlen(substring))
            {
                printf("%d", i - diff + 2);
                getch();
                exit(0);
            }
        }
        diff = strlen(substring) - strvalue[string[i - diff]] - 1 - count;
        if (diff > 0)
        {
            i = i + diff;
            diff = 0;
            count = 0;
        }
        else
            i++;
        if (i > strlen(string) + strlen(substring) + 2)
           getch();
           exit(0);

    }
}
Posted
Updated 7-Dec-10 5:52am
v4

1 solution

Hi,

Happily for you CodeProject organized a contest for a Diff[^] utility one year ago. My contribution[^] may help you start. Change the output to fit your needs.

Good luck,
AR
 
Share this answer
 
Comments
Dalek Dave 7-Dec-10 18:27pm    
Good old CP Archive!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900