这个程序光是判断是否回文字符的程序我会,但和文件联系起来我就弄不清楚了.:弄了2天了都没什么进展..
1.输入一个字符串。
2.在文件yeshuiwen.txt中查找这一字符串。
a.若有,则输出这一字符串是回文字符,且把这一字符串写入yeshuiwen中。
b.若没有,则在文件nohuiwen.txt中查找。
①若有,则输出这一字符串回文字符不是回文字符,且把这一字符串写入nohuiwen中。
②若没有,按判断回文算法判断。
Ⅰ.若是,则写入yeshuiwen中
Ⅱ.若不是,则写入nohuiwen中
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct string
{
char yelem[100];
char nelem[100];
int length;
}string1;
void main()
{
int n;
int i=0,j=n-1; 
char str3[80];
FILE *fp2;
char str2[200];
FILE *fp1;
char str1[200];
printf("请输入要判断的字符串");
scanf("%s",str1);
string1.length=strlen(str1);
if(strcmp(string1.yelem,str1)==0)
{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); /*关文件*/
}
else
if(strcmp(string1.nelem,str2)==0)
{printf("该字符串已经判断过,不是回文字符");
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); /*关文件*/
}
else
while(i<j) 
{ 
if(str3[i]==str3[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; 
} 
} 
if(i>=j)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); /*关文件*/
}
[此贴子已经被作者于2007-7-7 14:29:01编辑过]



 
											





 
	    

 
	

 
										
					
	