关于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出现的次数;

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