文件比较程序 [英] File compare program
本文介绍了文件比较程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个代码文件.我想比较两个文本文件,我想显示文本的差异.这将创建链接列表.首先,我将文本与链接列表集成在一起.我选择了博耶摩尔算法来比较字符串.我不知道合并两个代码文件.我发送了代码.非常感谢您的帮助. :)
用于链接列表
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
#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:
#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);
}
}
推荐答案
您很高兴CodeProject为 Diff [我的贡献 [
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
这篇关于文件比较程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文