C语言 输入字符写入文件再计算文件里的大写字母个数

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

main()
{
    FILE *fp;
    int num=0,i;
    char c,str1[100];

    printf("input string endwith enter:\n");
    gets(str1);
    
    fp=fopen("lhsbqb.txt","w");
    if(fp==NULL){printf("File open faild!");exit(0);}
    for(i=0;str1[i]!='\0';i++)
    {
        fputc(str1[i],fp);
    }
    fclose(fp);

    fp=fopen("lhsbqb.txt","r");
    if(fp==NULL){printf("File open faild!");exit(0);}
    while(1)
    {
        c=fgetc(fp);
        if(c==EOF)break;
        if(c>='A' && c<='Z')
        {
            num++;
        }
    }
    fclose(fp);
    printf("文件里有大字字母%d个",num);
    getchar();

}

http://www.pythonschool.com/python/13.html 转摘

原文地址:https://www.cnblogs.com/pythonschool/p/2729296.html