是的。。
天行健,君子以自强不息!!QQ:68660681
用fgetc改了,可还是不能运行
出现debug error
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 80
struct string
{
char yelem[100];
char nelem[100];
int length;
}string1;
void main()
{
char buf[MAX];
int count1 = 0,count2=0;
int i=0,j;
FILE *fp2;
FILE *fp1;
char str[200];
printf("请输入要判断的字符串");
scanf("%s",str);
string1.length=strlen(str);
j=string1.length-1;
if ((fp1 = fopen("yeshuiwen.txt", "r")) == NULL)
{
fprintf(stderr, "Error open the file.");
exit(1);
}
while (!feof(fp1))
{
fgets(buf, MAX, fp1); //读取一行文本,放入指定内存
count1++;
if ((strstr(buf, "count")) != NULL)
{
printf("该字符串已判断过,是回文字符");
fprintf(fp1,"%s , %7.2f\n",string1.yelem,string1.length); /* 写入文件*/
fclose(fp1); /*关文件*/}
}
if((fp2 = fopen("nohuiwen.txt", "r")) == NULL)
{
fprintf(stderr, "Error open the file.");
exit(1);
}
while(!feof(fp2))
{
fgets(buf, MAX, fp2); //读取一行文本,放入指定内存
count2++;
if ((strstr(buf, "count")) != NULL)
{ printf("该字符串已判断过,不是回文字符");
fprintf(fp2,"%s , %7.2f\n",string1.yelem,string1.length); /* 写入文件*/
fclose(fp2); /*关文件*/
}
}
while(i<j)
{
if(str[i]==str[j])
{
i++;
j--;
}
else
{ printf("这不是回文字符串\n");
if ((fp2=fopen("nohuiwen.txt","w"))==NULL) /*打开只写的文本文件*/
{
printf("cannot open file!");
exit(0);
}
fprintf(fp2,"%s , %7.2f\n",string1.nelem,string1.length); /* 写入文件*/
fclose(fp2); /*关文件*/
break;
}
printf("这是回文字符串");
if ((fp1=fopen("yeshuiwen.txt","w"))==NULL) /*打开只写的文本文件*/
{
printf("cannot open file!");
exit(0);
}
fprintf(fp1,"%s , %7.2f\n",string1.yelem,string1.length); /* 写入文件*/
fclose(fp1); /*关文件*/
}
}