-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADER.C
executable file
·128 lines (99 loc) · 2.1 KB
/
READER.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include "structs.h"
#include "reader.h"
int getFileSize(char *filename)
{
FILE * fp;
char c;
int counter = 0;
if ((fp = fopen(filename, "r")) == NULL)
{
printf("ERROR: NO FILE\n");
exit(1);
}
while ( (c = fgetc(fp)) != EOF)
{
if (c == '\n'){
counter++;
}
}
fclose(fp);
return counter;
}
void loadSolarFile(SYSTEM *list)
{
FILE * fp;
char c[100];
int ptrSolar;
int counter = 0;
if ((fp = fopen("system.sol", "r")) == NULL)
{
printf("ERROR: NO SOLAR FILE\n");
exit(1);
}
while (fgets(c, sizeof c, fp) != NULL)
{
int len = strlen(c);
int delimiter_pos = 0;
int i,valueCnt = 0;
char str_x[10] = "";
char str_y[10] = "";
char str_z[10] = "";
for(i=0; i < len; i++)
{
if(c[i] == DELIMITER_CHAR)
{
delimiter_pos = i;
valueCnt++;
continue;
}
if (valueCnt == 0)
{
str_x[i] = c[i];
}
if (valueCnt == 1)
{
if(i < (len-1))
str_y[i-(delimiter_pos+1)] = c[i];
}
if (valueCnt == 2)
{
if(i < (len-1))
str_z[i-(delimiter_pos+1)] = c[i];
}
}
list[counter].x = atoi(str_x);
list[counter].y = atoi(str_y);
list[counter].z = atoi(str_z);
counter++;
}
fclose(fp);
}
void saveFile(int ptrSize, SYSTEM *ptrList)
{
FILE *fp;
int i,limit;
long x,y,z,dz;
if( (fp = fopen("new.sol","w")) == NULL){
printf("IO ERROR");
exit(1);
}
for (i=0; i<ptrSize; i++)
{
limit = 1000/25;
x = ptrList[i].x;
y = ptrList[x].y;
if (x <= 500 && y <=500 && x >= -500 && y >= -500) limit = 1400/20;
if (x <= 400 && y <=400 && x >= -400 && y >= -400) limit = 1400/16;
if (x <= 300 && y <=300 && x >= -300 && y >= -300) limit = 1400/12;
if (x <= 200 && y <=200 && x >= -200 && y >= -200) limit = 1400/8;
if (x <= 100 && y <=100 && x >= -100 && y >= -100) limit = 1400/6;
z = rand() % (limit + 1 + limit) -limit;
fprintf(fp,"%ld;%ld;%ld\n",ptrList[i].x, ptrList[i].y, z);
ptrList[i].y = z;
}
getch();
fclose(fp);
}