提问人:maverk 提问时间:10/8/2023 最后编辑:Ryleymaverk 更新时间:10/8/2023 访问量:67
一种从相反顺序读取并忽略特定数量的字符的方法
a way to read from the reverse order and ignore a specific amount of characters
问:
我希望 C 语言中的程序以相反的顺序从特定部分读取文件,忽略特定数量的字符被打印。例如:
hello world
我想开始阅读,但我想忽略前 3 个字符,只打印world
wo
#include <stdio.h>
#define CHARACTER -1
int main(){
FILE *file = fopen("temp.txt", "r");
fseek(file, -3, SEEK_END);
char print ;
fseek(file, print = CHARACTER, SEEK_CUR);
char buffer[615];
fscanf(file, "%s", buffer);
printf("%c", print);
}
答: 暂无答案
评论
-1
-2
fread
fscanf
"%2s"
fseek
fscanf("%2s", buffer)
读取 2 个“字母”并添加一个到缓冲区......不正确的 C:......还要注意文件中常见的末尾换行符'\0'
seek(-5); scanf("%2s")