-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfseek.c
More file actions
47 lines (43 loc) · 1012 Bytes
/
fseek.c
File metadata and controls
47 lines (43 loc) · 1012 Bytes
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
46
47
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int chkint (char *arg);
main(int argc, char *argv[])
{
int input_char, position;
FILE *fp;
char *prog = argv[0]; /* program name for errors */
int num;
num = chkint(argv[1]);
printf("%d\n", num);
while (--argc > 1) {
printf("argc<%d>\n",argc);
if ((fp = fopen(argv[argc], "r")) == NULL) {
fprintf(stderr, "%s: can't open %s\n", prog, argv[argc]);
exit(1);
} else {
fseek(fp, num, SEEK_SET);
position = ftell (fp);
printf("position: %d\n", position);
input_char = getc (fp);
printf ("Character at position %d = '%c'.\n\n", position, input_char);
fclose(fp);
}
}
if (ferror(stdout)) {
fprintf(stderr, "%s: error writing stdout\n", prog);
exit(2);
}
exit(0);
}
int chkint (char *arg)
{
int num, i, length;
length = strlen(arg);
for (num=0, i=0; i < length; i++) {
if (! isdigit(arg[i]))
return -1;
num = 10 * num + (arg[i] - '0');
}
return num;
}