Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
caraun
/
kodunetooI
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
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
dd778f13
authored
Feb 28, 2023
by
caraun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
48ac7858
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
0 deletions
funktsioonid.c
funktsioonid.c
0 → 100644
View file @
dd778f13
#include "Header.h"
void
faili_nimi
(
char
*
nimi
,
char
*
tekst
){
//otsing faili nime järgi
printf
(
"%s"
,
tekst
);
scanf
(
"%s"
,
nimi
);
}
int
kontrolli_fail
(
FILE
*
F1
){
//kontrolli kas fail on olemas
if
(
F1
==
NULL
){
return
0
;
}
return
1
;
}
int
counter
(
FILE
*
F1
){
int
N
=
0
;
char
ch
;
while
((
ch
=
fgetc
(
F1
))
!=
EOF
){
if
(
ch
==
'\n'
)
{
N
++
;
}
}
return
N
;
}
void
loe_andmed
(
FILE
*
F1
,
int
*
N
){
//loe andmed failist
int
i
=
0
;
char
buff
[
59
];
double
buff2
;
int
buffi
;
while
(
fscanf
(
F1
,
"%s %lf %d"
,
buff
,
&
buff2
,
&
buffi
)
!=
EOF
){
//loome uued puhvrid kuhu andmeid salvestada
i
++
;
}
*
N
=
i
;
rewind
(
F1
);
//mine tagasi faili algusesse loe uued kirjed
}
void
loe_kaup
(
Toode
*
kaup
,
FILE
*
F1
){
//loe kaup ja nende andmed järjekorda
int
i
=
0
;
while
(
fscanf
(
F1
,
"%s %lf %d
\n
"
,
kaup
[
i
].
nimi
,
&
kaup
[
i
].
hind
,
&
kaup
[
i
].
kogus
)
!=
EOF
){
++
i
;
}
}
void
sort
(
Toode
tootearr
[],
int
*
N
){
//sorteeri vastavalt kauba kogusele ja hinnale
int
i
,
j
,
sorditud
;
Toode
temp
;
for
(
i
=
0
;
i
<
N
&&
sorditud
==
0
;
i
++
){
for
(
j
=
0
,
sorditud
=
1
;
j
<
N
-
i
-
1
;
j
++
){
if
(
tootearr
[
j
].
hind
>
tootearr
[
j
+
1
].
hind
){
temp
=
tootearr
[
j
];
tootearr
[
j
]
=
tootearr
[
j
+
1
];
tootearr
[
j
+
1
]
=
temp
;
sorditud
=
0
;
}
}
}
}
void
print
(
Toode
*
kaup
,
int
*
N
){
//prindi välja F1 nimekiri ekraanile
int
i
;
for
(
i
=
0
;
i
<
N
;
i
++
)
{
printf
(
"nimi = %s hind = %lf kogus %d
\n
"
,
kaup
[
i
].
nimi
,
kaup
[
i
].
hind
,
kaup
[
i
].
kogus
);
}
printf
(
"______________________________
\n
"
);
}
void
print2
(
Toode
*
kaup
,
int
*
N
){
//prindi välja kõik, mida saab osta
double
raha
;
printf
(
"Sisesta rahasumma
\n
"
);
scanf
(
"%lf"
,
&
raha
);
int
i
,
j
;
i
=
0
;
j
=
0
;
while
(
i
<
N
||
raha
<
kaup
[
i
].
hind
){
if
(
kaup
[
i
].
hind
<=
raha
&&
kaup
[
i
].
kogus
>
0
){
raha
-=
kaup
[
i
].
hind
;
//arvestatakse maha ja palju jaab jargi
kaup
[
i
].
kogus
--
;
j
++
;
}
else
if
(
kaup
[
i
].
hind
<=
raha
){
//kauba hind on vaiksem voi vordne rahaga
printf
(
"Te saate osta %d %s
\n
"
,
j
,
kaup
[
i
].
nimi
);
i
++
;
j
=
0
;
}
else
{
printf
(
"Te saate osta %d %s
\n
"
,
j
,
kaup
[
i
].
nimi
);
break
;
}
}
}
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