#include <stdio.h> #include<string.h> int main() { int i,ch; char str[100]; FILE *fp; fp=fopen("myfile","w"); //创建一个文件 while(1) { printf("input string:\n"); gets(str); fprintf(fp,"%s",str); printf("continue?"); ch=getchar(); if ((ch=='N')||(ch=='n')) break; getchar(); } fclose(fp); fp=fopen("myfile","r"); //开始读取文件 while(fscanf(fp,"%s",str)!=EOF) { for (i=0;str[i]!='\0';i++) { if ((str[i]>='A') && (str[i]<='Z')) //大小写转换 str[i]+=32; } printf("%s\n",str); } fclose(fp); return 0;
时间: 2024-10-11 22:05:15