运行出错,求大神来改一下
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <string.h>
#include <list>
#include <conio.h>
char path1[200];
char path2[200];
using namespace std;
list <string *> mylist1;
list <string *> mylist2;
list <string *> mylist3;
char * replace(char *srcp,char* subp,char *dstp)
{
int pos =0;
int offset =0;
int srcLen, subLen, dstLen;
srcLen = strlen(srcp);
subLen = strlen(subp);
dstLen = strlen(dstp);
char*pRet = NULL;
pRet = (char*)malloc(srcLen + dstLen - subLen +1);
{
pos = strstr(srcp, subp) - srcp;
memcpy(pRet, srcp, pos);
offset += pos;
memcpy(pRet + offset, dstp, dstLen);
offset += dstLen;
memcpy(pRet + offset, srcp + pos + subLen, srcLen - pos - subLen);
offset += srcLen - pos - subLen;
*(pRet + offset) ='\0';
}
memcpy(srcp,pRet,strlen(pRet)+1);
free(pRet);
return pRet;
}
void menu()
{
int i;
i=3;
system("color e1");
printf(" %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c\n",i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i);
printf(" %c %c\n",i,i);
printf(" %c %c\n",i,i);
printf(" %c %c\n",i,i);
printf(" %c %c\n",i,i);
printf(" %c Welcome 欢迎进入字符串统计系统 %c\n",i,i);
printf(" %c %c 制作人:\n",i,i);
printf(" %c %c 吕亮 \n",i,i);
printf(" %c %c 戚远航\n",i,i);
printf(" %c %c 林星\n",i,i);
printf(" %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c\n",i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i);
}
void openfile(char *filename1,char *filename2)
{
char str[200];
FILE *fp;
fp = fopen(filename1,"r+");
while(fgets(str,1000,fp))
{
char * p =strtok(str," \t");
while(p!=NULL)
{
string *str = new string(p);
mylist1.push_back(str);
p = strtok( NULL, " \t");
}
}
fclose(fp);
fp = fopen(filename2,"r+");
while(fgets(str,200,fp))
{
char * p =strtok(str," \t");
while(p!=NULL)
{
string *str = new string(p);
mylist2.push_back(str);
p = strtok( NULL, " \t");
}
}
fclose(fp);
}
void shanchu()
{
int i,j=0,k=0;
char s[200],*p ,*q,del_x;
printf("请选择进行删除处理的字符串:\n");
printf("1.对第一个文本进行删除处理\n");
printf("2.对第二个文本进行删除处理\n");
scanf("%d",&i);
switch(i)
{
case(1):{for(j=0,k=0;path1[k]!='\0';j++,k++)
s[j]=path1[k];
};break;
case(2):{for(j=0,k=0;path2[k]!='\0';j++,k++)
s[j]=path2[k];
};break;
default:printf("输入有误,请重新输入.\n");system("pause");shanchu();
}
/*fflush(stdin);
printf("输入要删除的字符:");
scanf("%c",&del_x);
for(p=s,q=s;*p!='\0';p++)
if(*p!=del_x)*q++=*p;
{*q=*p;}
printf("删除后字符串为:\n");*/
puts(s);
printf("\n");
}
void bijiao()
{
list <string *>::iterator iter1;
list <string *>::iterator iter2;
for(iter1=mylist1.begin();iter1!=mylist1.end();iter1++)
{
string str1 = *(*iter1);
for(iter2=mylist2.begin();iter2!=mylist2.end();iter2++)
{
string str2 = *(*iter2);
if((str2)==0)
{
string *str3 = new string(str1);
mylist3.push_back(str3);
break;
}
}
}
}
void main()
{
void shanchu();
menu();
printf("请输入第一个文本文件的路径:\n");
gets(path1);
printf("请输入第二个文本文件的路径:\n");
gets(path2);
replace(path1,"\\","\\\\");
replace(path2,"\\","\\\\");
puts(path1);
puts(path2);
openfile(path1,path2);
bijiao();
printf("相同的字符串有:");
int max = 0;
string maxstr;
list <string *>::iterator iter3;
for(iter3=mylist3.begin();iter3!=mylist3.end();iter3++)
{
string str1 = *(*iter3);
if(max <= str1.length())
{
max = str1.length();
maxstr=str1;
}
printf(str1.data());
printf("\n");
}
printf("\n\n");
printf("相同的字符串有:%d条\n",mylist3.size());
printf("最大的相同的字符串为:%s\n",maxstr.data());
system("pause");
shanchu();
}