50067. Walk in a File

難度:3/5

記得fseek用法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

int main(){
char s[128];
scanf("%s", s);
FILE* fp = fopen(s, "rb");
while(1){
int type, para;
if(fread(&type, sizeof(int), 1, fp) != 1) break;
if(fread(&para, sizeof(int), 1, fp) != 1) break;

if(type == 0){
printf("%d", para);
}
else if(type == 1){
for(int i = 0; i < 4; i++){
printf("%c", (para >> (8 * i) & (0xff)));
}
}
else if(type == 2){
char c;
while(c = fgetc(fp)){
if(c == '\0') break;
else putchar(c);
}
}
else if(type == 3){
fseek(fp, para - 8, SEEK_CUR);
}
else if(type == 4){
fseek(fp, para, SEEK_SET);
}
else if(type == 5){
fseek(fp, para, SEEK_END);
}
else{
break;
}
}
printf("Seek end\n");
fclose(fp);
}


50067. Walk in a File
https://aaronlin1229.github.io/judgegirl_50067/
Author
Akizumi
Posted on
July 17, 2023
Licensed under