sw911911 2022-12-13 22:30 采纳率: 50%
浏览 96
已结题

关于c语言的实践活动

.将以下字符串复制到一个明文"test. txt”的文件中:
Hairy Poter is a series of seven fantasy novels write by British author J. K. Rowling. The
novels chronicle the lives of a young wizard, Hairy Poter, and his friends Hermione Gang
er and Ron Wesley, al of whom are students at Hogwarts School of Witchcraft and Wiz
dry. The main story arc concerns Hairy’s struggle against Lord Voldemort, a dark wizard w
ho intends to become immortal, overthrow the wizard governing body known as the Minis
ry of Magic and subjugate all wizards and Mules (non-magical people)
使用File l/0的方式读取test.txt,编程实现以下功能
a)将test.txt中所有的字符逆序打印在屏幕上;
b)统计test.txt中字符e出现的次数;

  • 写回答

1条回答 默认 最新

  • 语言-逆行者 2022-12-13 22:42
    关注

    img

    
    #define _CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    #include<string.h>
    int main()
    {
        FILE* fptr;
        fptr = fopen("test.txt", "r");
        char str[6][100];
        int i,j,k,count=0;
        if (fptr == NULL)
        {
            printf("Error!");
        }
        for (i = 0; i < 6; i++) 
        {
            fgets(str[i], 100, fptr);
        }
        fclose(fptr);
        printf("逆序输出:\n");
        for (i = 5; i >= 0; i--) {
            j = strlen(str[i]);
            for (k = j - 1; k >= 0; k--) 
            {
                if (str[i][k] == 'e')
                {
                    count++;
                }
                printf("%c", str[i][k]);
            }
            printf("\n");
        }
        printf("\n");
        printf("字符e出现的次数为:%d\n",count);
        
    
        return 0;
    }
    
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 12月22日
  • 已采纳回答 12月14日
  • 创建了问题 12月13日

悬赏问题

  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目