-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand3.c
38 lines (30 loc) · 858 Bytes
/
command3.c
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
#include <stdio.h>
#include <stdlib.h>
#include "command3.h"
#include "open_close.h"
#include "print_msg.h"
//verifica se o rrn lido do teclado indica uma posicao valida no arquivo
int record_position(FILE* file, int pos){
fseek(file, 0, SEEK_END);
if (pos > ftell(file)) {
rrn_error_msg();
return -1; //erro, rrn invalido
}
fseek(file, pos, SEEK_SET);
return 0; //sucesso
}
void command_3(char* filename) {
FILE* file = open_file(filename, FILE_READB);
if (file == NULL) {
return;
}
int RRN;
scanf("%d", &RRN); //recebe um rrn do teclado
int pos = RRN * TAM_REG; //formula para byte offset
if (record_position(file, pos) == -1){
return;
}
//imprime os campos do registro com o rrn lido
print_fileds(file);
close_file(file); //fecha o arquivo usado
}