C 练习实例98

C语言教程1

C 练习实例98

题目:从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文件"test"中保存。 输入的字符串以!结束。

程序分析:无。文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili98.html

实例

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
    FILE*fp=NULL;
    char str[50];
    int i,len;
    printf("输入一个字符串:\n");
    gets(str);
    len=strlen(str);
    for(i=0;i<len;i++)
    {
        if(str[i]<='z'&&str[i]>='a')
            str[i]-=32;
    }
    if((fp=fopen("test","w"))==NULL)
    {
        printf("error: cannot open file!\n");
        exit(0);
    }
    fprintf(fp,"%s",str);
    fclose(fp);

    system("pause");
    return 0;
}

以上实例运行输出结果为:文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili98.html

输入一个字符串:
www.gongshiku.com
文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili98.html文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili98.html
运营不易,
感谢支持!
weinxin
我的微信
我的微信公众号
我的微信公众号扫一扫
weinxin
我的公众号
 最后更新:2021-12-7
公式库网
  • 本文由 公式库网 发表于 2021年12月6日21:37:59
  • 转载请务必保留本文链接:https://www.gongshiku.com/html/202112/c-lianxishili98.html

发表评论