Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
mvahes
/
Lennubroneerimis_tarkvara
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8970cfb7
authored
2 years ago
by
karade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update generator.c
parent
2199259b
Inimeste_generaator
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
32 deletions
generator.c
generator.c
View file @
8970cfb7
/**
* File: generator.c
* Author: Risto Heinsar
* Created: 12.03.2015
* Modified 14.03.2023
*
* Description: This is a random data generator
*
* Note: This is a starter code for a lab task
*/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
...
...
@@ -44,43 +35,62 @@ int main(void)
users
data
[
SEATS
];
users
data
[
SEATS
]
=
{
0
}
;
int
i
;
int
i
,
j
;
char
seat
[
4
];
char
month
[
STR_MAX
];
char
date
[
DOB_MAX
];
char
email
[
STR_MAX
];
char
mail
[
STR_MAX
];
char
docNum
[
DOC_MAX
];
char
letters
[
26
]
=
{
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
};
for
(
i
=
0
;
i
<
nameCount
;
i
++
)
{
strcpy
((
data
+
i
)
->
lName
,
lastNames
[
GetRand
(
0
,
fir
stNamePoolSize
-
1
)]);
strcpy
((
data
+
i
)
->
fName
,
firstNames
[
GetRand
(
0
,
la
stNamePoolSize
-
1
)]);
strcpy
((
data
+
i
)
->
lName
,
lastNames
[
GetRand
(
0
,
la
stNamePoolSize
-
1
)]);
strcpy
((
data
+
i
)
->
fName
,
firstNames
[
GetRand
(
0
,
fir
stNamePoolSize
-
1
)]);
printf
(
"TEST: %s
\n
"
,
(
data
+
i
)
->
fName
);
do
//leitakse random istekoht, kuni funktsioon tagastab et
{
//kellegil pole seda istkohta otsitakse uus.
strcpy
(
seat
,
seats
[
GetRand
(
0
,
seatPoolSize
-
1
)]);
}
while
(
GetUniqueSeat
(
data
,
i
,
*
seats
,
SEATS
,
seat
)
>
0
);
}
while
(
GetUniqueSeat
(
data
,
i
,
seat
)
>
0
);
strcpy
((
data
+
i
)
->
seat
,
seat
);
//eeldusel et eelmine tsükkel
//lõpetab kopeeritakse istekoht struktuurimassiivi
strcpy
(
month
,
months
[
GetRand
(
0
,
monthPoolSize
-
1
)]);
GenerateDateOfBirth
(
month
,
date
);
strcpy
((
data
+
i
)
->
dateOfBirth
,
date
);
GenerateDateOfBirth
(
month
,
date
);
//funktsioonis pannakse numbrid
strcpy
((
data
+
i
)
->
dateOfBirth
,
date
);
//ja kuu kokku et saada
//formaadis sünnikuupäev
strcpy
((
data
+
i
)
->
residency
,
residencies
[
GetRand
(
0
,
residencyPoolSize
-
1
)]);
(
data
+
i
)
->
checkedIn
=
false
;
(
data
+
i
)
->
checkedIn
=
false
;
//default kõigile
memset
(
mail
,
0
,
sizeof
(
mail
));
//tühjendab sõne enne uue meili loomist
mail
[
0
]
=
(
data
+
i
)
->
fName
[
0
];
mail
[
strlen
(
mail
)]
=
'.'
;
//emaili loomine, null terminaatoreid on
mail
[
strlen
(
mail
)]
=
'\0'
;
//palju et tagada strcati funktsionaalsus
strcat
(
mail
,(
data
+
i
)
->
lName
);
mail
[
strlen
(
mail
)]
=
'\0'
;
strcat
(
mail
,
emails
[
GetRand
(
0
,
emailPoolSize
-
1
)]);
mail
[
strlen
(
mail
)]
=
'\0'
;
printf
(
"%s
\n
"
,
mail
);
strcpy
((
data
+
i
)
->
email
,
mail
);
email
[
0
]
=
(
data
+
i
)
->
fName
[
0
];
email
[
strlen
(
email
)]
=
'.'
;
strcat
(
email
,(
data
+
i
)
->
lName
);
strcat
(
email
,
emails
[
GetRand
(
0
,
emailPoolSize
-
1
)]);
email
(
strlen
(
email
))
=
'\0'
;
printf
(
"%s
\n
"
,
email
);
for
(
j
=
0
;
j
<
2
;
j
++
)
{
docNum
[
j
]
=
letters
[
GetRand
(
0
,
23
)];
}
for
(
j
=
2
;
j
<
9
;
j
++
)
//dokumendi numbri genereerimine
{
docNum
[
j
]
=
'0'
+
GetRand
(
0
,
9
)
%
10
;
}
docNum
[
9
]
=
'\0'
;
strcpy
((
data
+
i
)
->
documentNum
,
docNum
);
strcpy
(
email
,
""
);
(
data
+
i
)
->
luggageClass
=
GetRand
(
0
,
3
);
}
...
...
@@ -90,6 +100,7 @@ int main(void)
return
EXIT_SUCCESS
;
}
void
GenerateDateOfBirth
(
char
*
month
,
char
*
dateOB
)
{
...
...
@@ -100,10 +111,12 @@ void GenerateDateOfBirth(char *month, char *dateOB)
snprintf
(
temp
,
5
,
"%d"
,
date
);
strcat
(
dob
,
temp
);
dob
[
strlen
(
dob
)]
=
'\0'
;
dob
[
strlen
(
dob
)]
=
'.'
;
strcat
(
dob
,
month
);
dob
[
strlen
(
dob
)]
=
'\0'
;
dob
[
strlen
(
dob
)]
=
'.'
;
snprintf
(
temp
,
5
,
"%d"
,
year
);
...
...
@@ -115,7 +128,7 @@ void GenerateDateOfBirth(char *month, char *dateOB)
}
int
GetUniqueSeat
(
users
*
data
,
int
len
,
c
onst
char
*
seats
,
int
size
,
c
har
*
seat
)
int
GetUniqueSeat
(
users
*
data
,
int
len
,
char
*
seat
)
{
int
match
=
0
;
//Otsib kas on kellegil juba sama istekoht
...
...
@@ -147,9 +160,10 @@ void GenNames(users *data, int num)
for
(
i
=
0
;
i
<
num
;
i
++
)
{
fprintf
(
fp
,
"%s %s %s %s %s
\n
"
,(
data
+
i
)
->
fName
,
(
data
+
i
)
->
lName
,(
data
+
i
)
->
dateOfBirth
,
(
data
+
i
)
->
residency
,
(
data
+
i
)
->
seat
);
fprintf
(
fp
,
"%s %s %s %s %s %s %s %d
\n
"
,(
data
+
i
)
->
documentNum
,
(
data
+
i
)
->
fName
,(
data
+
i
)
->
lName
,(
data
+
i
)
->
dateOfBirth
,
(
data
+
i
)
->
email
,(
data
+
i
)
->
residency
,
(
data
+
i
)
->
seat
,
(
data
+
i
)
->
luggageClass
);
}
fclose
(
fp
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment