比较字符型数组

zzcc880517 2008-04-26 12:22:15
我想比对两个txt文件中部分内容是否一样,于是把它们分别读入两个字符型数组n和n1中,用了int result=strcmp(n,n1),明明txt文件中内容一样,但c就不等于0,很费解,拜托高手帮忙,多谢啦!
注:Address.txt已存在
void CChange::OnButton1()
{
// TODO: Add your control notification handler code here
CString changename;
CString changenumber;
CString changeemail;
CString ss("");
CString aa("");
CString oo("");
char *cha,*chn,*che;
char n1[20],n[20];
m_changename1.GetWindowText(changename);
m_changenumber1.GetWindowText(changenumber);
m_changeemail1.GetWindowText(changeemail);
cha=changename.GetBuffer(changename.GetLength());
chn=changenumber.GetBuffer(changenumber.GetLength());
che=changeemail.GetBuffer(changeemail.GetLength());
changename.ReleaseBuffer();
changenumber.ReleaseBuffer();
changeemail.ReleaseBuffer();
ss=ss+"过长,重新输入";
oo=oo+"通讯录中无此人";
aa=aa+cha+' '+chn+' '+che;
if(changename.GetLength()<21&&changenumber.GetLength()<21&&changeemail.GetLength()<19){
ofstream outfile;
outfile.open("N.txt",ios::out);
outfile.flags(ios::right);outfile.width(20);
outfile<<cha;
outfile.close();
ifstream infile;
infile.open("N.txt",ios::in);
infile.read(n,20);
infile.close();
CFile hh;
hh.Open("D:\\c++\\作业\\名片管理系统\\AddressBook.txt",CFile::modeRead);
int kk=hh.GetLength();
hh.Close();
int ll=kk/80;
for(int k=0;k<ll;){
ifstream infile1;
infile1.open("AddressBook.txt",ios::in);
int s=80*k;
infile1.seekg(s);
infile1.read(n1,20);
infile1.close();
int result=strcmp(n,n1);
if (result==0){
ofstream outfile1;
outfile1.open("AddressBook.txt",ios::ate);
outfile1.seekp(40*((2*k)+1),ios::beg);
outfile1.flags(ios::right);outfile1.width(20);
outfile1<<chn;
outfile1.flags(ios::right);outfile1.width(18);
outfile1<<che;
outfile1<<'\n';
outfile1.close();
m_show1.SetWindowText(aa);
break;}
else
k++;
if(k==ll)
m_show1.SetWindowText(oo);
}
}
else
m_show1.SetWindowText(ss);
}
...全文
183 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzcc880517 2008-05-03
  • 打赏
  • 举报
回复
谢谢各位大侠,我已经找到解决问题的办法啦!其实蛮简单的.
clhposs 2008-04-26
  • 打赏
  • 举报
回复
比对两个txt文件中部分内容是否一样
可以调用system();
利用DOS来 -_-!
qiuqiu173 2008-04-26
  • 打赏
  • 举报
回复
你先把n,n1打印出来看看,注意结尾是否是空格回车之类的

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧