資源簡介
C語言版文件相似度對比,文本對比
數據結構C語言大作業
采用遞歸矩陣對比,用了結構體
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#define??MAX_INT (?(?(unsigned?int)?(-1)?)?>>?1)
#define??MIN_INT MAX_INT?+?1
struct?compareText?{
int differenceStepValue;
wchar_t?*?text1;
wchar_t?*?text2;
};
int?getLength(?wchar_t??*str?);
float?similarityCalculate(?wchar_t??*str1int?pieceLength1?wchar_t??*str2?int?pieceLength2char?isShowMatrix);
int?getMax(?int?num1?int?num2?);
int?getMin(?int?num1?int?num2?int?num3?);
void?showMatrix(?compareText?**matrix?wchar_t??*str1?int?len1?wchar_t??*str2?int?len2?);
wchar_t?*?getFileContent(?char*?path?);
wchar_t?*?deleteOthers(?wchar_t?*?str?);
wchar_t?*?char2wchar(?char*?cp?);
void?del_chr(?wchar_t?*s?wchar_t?ch?);
int?setLogFile(char?*result);
void?toSimilarityCalculate(char?*path1char?*path2);
void?toSimilarityCalculateMenu();
void?toListLogMessage();
void?menu();
int?isFileExist(char?*path);
typedef?struct?compareText?compareText;
int?main(?void?)
{
setlocale(?LC_CTYPE?“chs“?);?/*?設置中文運行環境?*/
menu();
return(0);
}
/**
?*? 總目錄菜單
?*/
void?menu(){
int?isClear?=?1;
while(1){
if(isClear?==?1){
system(“cls“);
}else{
printf(“\n“);
}
int?choose?=?-1;
printf(“輸入功能序號進行操作:\n“);
printf(“1.對比兩個文件的相似度\n“);
printf(“2.查看歷史對比記錄\n“);
printf(“3.直接退出\n“);
printf(“請輸入序號:“);
fflush(stdin);
scanf(“%d“&choose);
if(choose?==?1){
system(“cls“);
isClear?=?0;
toSimilarityCalculateMenu();
}else?if(choose?==?2){
system(“cls“);
isClear?=?0;
toListLogMessage();
}else?if(choose?==?3){
isClear?=?0;
break;
}else{
system(“cls“);
isClear?=?0;
printf(“請輸入正確的序號!\n“);
}
}
}
/**
?*? 字符串相似度處理目錄菜單
?*/
void?toSimilarityCalculateMenu(){
system(“cls“);
char?choose;
char?*path1?=?(char*)malloc(sizeof(char)?*?100);
char?*path2?=?(char*)malloc(sizeof(char)?*?100);
printf(“請輸入第一個文件的路徑(目錄下有測試文件text1.txt):“);
fflush(stdin);
scanf(“%s“path1);
while(isFileExist(path1)?==?0){
printf(“文件不存在或不可讀,請重新輸入文件路徑:“);
fflush(stdin);
scanf(“%s“path1);
}
printf(“請輸入第二個文件的路徑(目錄下有測試文件text2.txt):“);
fflush(stdin);
scanf(“%s“path2);
while(isFileExist(path2)?==?0){
printf(“文件不存在或不可讀,請重新輸入文件路徑:“);
fflush(stdin);
scanf(“%s“path2);
}
printf(“\n是否開始進行相似度對比(Y/N):“);
fflush(stdin);
scanf(“%c“&choose);
while(1){
if(choose?==?‘Y‘?||?choose?==?‘y‘){
toSimilarityCalculate(path1path2);
break;
}else?if(choose?==?‘N‘?||?choose?==?‘n‘){
break;
}else{
printf(“輸入錯誤,請重新輸入(Y/N):“);
fflush(stdin);
scanf(“%c“&choose);
continue;
}
}
}
/**
?*? 相似度處理計算流程
?*/
void?toSimilarityCalculate(char?*path1char?*path2){
char?choose?=?‘n‘;
printf(“〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n“);
printf(“正在進行文件相似度對比...\n“);
Sleep(300);
printf(“正在獲取第一個文件(%s)的內容...\n“path1);
Sleep(1000);
wchar_t
評論
共有 條評論