从键盘输入一个字符串,将其中的小写字母全部转换成大写字母,然后输出到一个
生盘文件“test”中保存,输入的字符串以“!”结束。
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { FILE*fp; char str[100]: int i=0; if((fp=fopen("al","w"))==NULL) {printf("can not open file\n”); exit(0); } printf("input a string:\n"); gets(str); while(str[i]!=’!’) {if(str[i]>=’a'&&str[i]<=’z’) str[i]=str[i]-32; fputc(str[i],fp); i++; } fclose(fp); fp=fopen("al","r"); fgets(str,strlen(str)+1,fp); printf("%s\n",str); fclose(fp); return 0; }
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
FILE*fp;
char str[100]:
int i=0;
if((fp=fopen("al","w"))==NULL)
{printf("can not open file\n”);
exit(0);
}
printf("input a string:\n");
gets(str);
while(str[i]!=’!’)
{if(str[i]>=’a'&&str[i]<=’z’)
str[i]=str[i]-32;
fputc(str[i],fp);
i++;
fclose(fp);
fp=fopen("al","r");
fgets(str,strlen(str)+1,fp);
printf("%s\n",str);
fclose(fp);
return 0;
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题