-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathSkorobogatov.c
53 lines (48 loc) · 1.22 KB
/
Skorobogatov.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLENGTH 255
typedef struct
{
int number;
char string[MAXLENGTH];
float othernumber;
} readthing;
int main(int argc, const char * argv[]) {
readthing *thing = malloc(sizeof(readthing));
char path[MAXLENGTH];
FILE *file;
if (argc != 2)
{
printf("Enter the filepath\n");
fgets(path, MAXLENGTH, stdin);
path[strlen(path)-1] = '\0';
if ((file = fopen(path, "r+b")) == NULL)
{
printf("file does not exist\n");
return 0;
}
} else
if ((file = fopen(argv[1], "r+b")) == NULL)
{
printf("file does not exist\n");
return 0;
}
/*if ((file = fopen("/Users/denisskorobogatov/Desktop/lab1/lab1/data.dat", "r+b")) == NULL)
{
printw("file does not exist\n");
endwin();
return 0;
}*/
int i = 0;
while (!feof(file))
{
fread(thing, sizeof(readthing), 1, file);
printf("%d %s %f\n", thing->number, thing->string, thing->othernumber);
i++;
}
printf("Element amount: %d\n", i-1);
printf("File size: %ld\n", ftell(file));
fclose(file);
return 0;
}