-
大小: 15KB文件類型: .cpp金幣: 1下載: 0 次發(fā)布日期: 2021-06-15
- 語(yǔ)言: C/C++
- 標(biāo)簽: C語(yǔ)言??文本對(duì)比??數(shù)據(jù)結(jié)構(gòu)??
資源簡(jiǎn)介
C語(yǔ)言版文件相似度對(duì)比,文本對(duì)比
數(shù)據(jù)結(jié)構(gòu)C語(yǔ)言大作業(yè)
采用遞歸矩陣對(duì)比,用了結(jié)構(gòu)體
代碼片段和文件信息
#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“?);?/*?設(shè)置中文運(yùn)行環(huán)境?*/
menu();
return(0);
}
/**
?*? 總目錄菜單
?*/
void?menu(){
int?isClear?=?1;
while(1){
if(isClear?==?1){
system(“cls“);
}else{
printf(“\n“);
}
int?choose?=?-1;
printf(“輸入功能序號(hào)進(jìn)行操作:\n“);
printf(“1.對(duì)比兩個(gè)文件的相似度\n“);
printf(“2.查看歷史對(duì)比記錄\n“);
printf(“3.直接退出\n“);
printf(“請(qǐng)輸入序號(hào):“);
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(“請(qǐng)輸入正確的序號(hào)!\n“);
}
}
}
/**
?*? 字符串相似度處理目錄菜單
?*/
void?toSimilarityCalculateMenu(){
system(“cls“);
char?choose;
char?*path1?=?(char*)malloc(sizeof(char)?*?100);
char?*path2?=?(char*)malloc(sizeof(char)?*?100);
printf(“請(qǐng)輸入第一個(gè)文件的路徑(目錄下有測(cè)試文件text1.txt):“);
fflush(stdin);
scanf(“%s“path1);
while(isFileExist(path1)?==?0){
printf(“文件不存在或不可讀,請(qǐng)重新輸入文件路徑:“);
fflush(stdin);
scanf(“%s“path1);
}
printf(“請(qǐng)輸入第二個(gè)文件的路徑(目錄下有測(cè)試文件text2.txt):“);
fflush(stdin);
scanf(“%s“path2);
while(isFileExist(path2)?==?0){
printf(“文件不存在或不可讀,請(qǐng)重新輸入文件路徑:“);
fflush(stdin);
scanf(“%s“path2);
}
printf(“\n是否開(kāi)始進(jìn)行相似度對(duì)比(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(“輸入錯(cuò)誤,請(qǐng)重新輸入(Y/N):“);
fflush(stdin);
scanf(“%c“&choose);
continue;
}
}
}
/**
?*? 相似度處理計(jì)算流程
?*/
void?toSimilarityCalculate(char?*path1char?*path2){
char?choose?=?‘n‘;
printf(“〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n“);
printf(“正在進(jìn)行文件相似度對(duì)比...\n“);
Sleep(300);
printf(“正在獲取第一個(gè)文件(%s)的內(nèi)容...\n“path1);
Sleep(1000);
wchar_t
評(píng)論
共有 條評(píng)論