forked from mireamirea/ikbo-4-lab-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sidorenko Mikhail.c
72 lines (66 loc) · 1.33 KB
/
Sidorenko Mikhail.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ERROR_FILE_OPEN -3
#define LENGHT_STRING_INPUT 256
struct FileSegment
{
int a;
char str[255];
float f;
};
void PrintFileSegment(struct FileSegment a)
{
printf("%d\t%s\t%f\n", a.a, a.str, a.f);
}
void OpenArg(int argc, char ** argv, char * strFile, FILE ** input)
{
int i = 0;
if (argc > 1)
{
for (i = strlen(argv[1]); i >= 0 && i < LENGHT_STRING_INPUT; i--)
{
strFile[i] = argv[1][i];
}
*input = fopen(strFile, "rb");
if (*input == NULL)
{
printf("File in argument not found.\n");
strFile[0] = 0;
}
else
{
printf(strFile);
}
}
}
int main(int argc, char ** argv)
{
FILE * input = NULL;
char strFile[LENGHT_STRING_INPUT] = { 0 };
struct FileSegment buffer = { 0, {0}, 0 };
int i;
int count = 0;
printf("Starting...\n");
OpenArg(argc, argv, strFile, &input);
if(strFile[0] == 0) do
{
puts("No arguments.\nFilename: ");
scanf("%s", strFile);
input = fopen(strFile, "rb");
if (input == NULL)
{
puts("File not found.\n");
}
} while (input == NULL);
do
{
i = fread(&buffer, sizeof(struct FileSegment), 1, input);
if (i > 0)
{
count++;
PrintFileSegment(buffer);
}
} while (i > 0);
printf("SIZE: %ld", count * sizeof(struct FileSegment));
}