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日