比较这几个文件,把重复的输出在一个文本文件中~在线等
/root/posapl/include/hposdefdmcommon.h
/root/posapl/include/libTGSock.h
/root/posapl/include/opeinfstr.h
/root/posapl/include/TG8583.h
/root/posapl/include/TGCre.h
/root/posapl/src/appc/appcmain.c
/root/posapl/src/aprpt/configure.in
/root/posapl/src/aprpt/actual/configure.in
/root/posapl/src/aprpt/actual/Makefile.am
/root/posapl/src/aprpt/common/configure.in
/root/posapl/src/appc/autogen.sh
/root/posapl/src/appc/configure.in
/root/posapl/src/appc/Makefile.am
/root/posapl/src/aprpt/configure.in
/root/posapl/src/aprpt/actual/configure.in
/root/posapl/src/aprpt/actual/Makefile.am
/root/posapl/src/aprpt/common/configure.in
把重复的输出在一个文本文件中~在线等 用C语言~~
[解决办法]
//将out.txt文件中的内容排序并去重,结果保存到unique.txt中#include <stdio.h>#include <stdlib.h>#define MAXLNO 10000000 //能处理的最大行数#define MAXLEN 20 //能处理的最大行宽,包括行尾的\n和字符串尾的\0char buf[MAXLNO][MAXLEN];int ln,i;FILE *f;int cmpfun( const void *arg1, const void *arg2 ) { return strcmp((const char *)arg1,(const char *)arg2);}int main() { f=fopen("out.txt","r"); if (NULL==f) { printf("Can not find file out.txt\n"); return 1; } ln=0; while (1) { if (NULL==fgets(buf[ln],MAXLEN,f)) break; ln++; if (ln>=MAXLNO) { printf("Lines >%d ignored.",MAXLNO); break; } } fclose(f); if (ln>1) qsort(buf,ln,MAXLEN,cmpfun); f=fopen("unique.txt","w"); if (NULL==f) { printf("Can not create file unique.txt\n"); return 2; } fprintf(f,"%s",buf[0]); if (ln>1) for (i=1;i<ln;i++) { if (strcmp((const char *)buf[i-1],(const char *)buf[i])) fprintf(f,"%s",buf[i]); } fclose(f); return 0;}