#include<stdio.h>
#include<stdlib.h>
#define MAX 3000
int main()
{
FILE *fp1;
FILE *fp2;
char c='1';
char chc[3];
int m;
char ch[MAX];
int j;int t=0;int i=0;
fp1=fopen("C:\\Documents and Settings\\Raul\\桌面\\招聘测试\\cihai_000.xml","r");
if(fp1==NULL)
{
printf("file can't open");
exit(1);
}
fp2=fopen("C:\\Documents and Settings\\Raul\\桌面\\结果.txt","w");
if(fp2==NULL)
{
printf("file can't open");
exit(1);
}
c=getc(fp1);
do
{
ungetc(c,fp1);
while(c!='#')
c=getc(fp1);
if(((c=getc(fp1))=='B')&&((c=getc(fp1))=='Z'))
//if((c=getc(fp1))=='Z')
for(m=0;m<=2;m++) chc[m]=getc(fp1); chc[m]='\0';
ch[i++]=chc[0]; //用字符数组记录以”BZ”开头的字。
j=0;
while(j<=i-2)
{if(ch[j]!=chc[0]) j++;}
if(j==i-1)
{ fputs("#BZ",fp2);
fputs(chc,fp2);
putc('\n',fp2);
t++; //用t记录不相同的个数。
}
fprintf(fp2,"共有%d个不同的字",t);
}
while ((c=getc(fp1))!=EOF);
fclose(fp1);
fclose(fp2);
return 0;
}
char chc[3];
改为
char chc[4];