.将以下字符串复制到一个明文"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出现的次数;

关于c语言的实践活动
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 语言-逆行者 2022-12-13 22:42关注
#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; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录