Commit 21fc9dfc by trkall

esimese tunni asjad

parents
File added
#include <stdio.h>
/*
Funktsioonidega failist lugemine ja failist saadud arvude liitmine kahe kaupa
ning lpuks vastuste vlja printimine
*/
#define MAX 15
int *sisse(FILE *arvud)
{
int i;
int *arv;
for (i=0;i<MAX;i++)
{
fscanf(arvud, "%d\n", (arv+i));
}
return arv;
}
int *arvut(int *arr)
{
int i;
int j = 0;
int *arv;
for (i=0;i<MAX/2;i++, j+=2)
{
*(arv+i)=*(arr+j)+*(arr+(j+1));
}
*(arv+6) += *(arr+14);// viimase arvutusega liidame ka 15. arvu eelmisele kahele
return arv;
}
void faili(int *arr)
{
FILE *fin;
int i;
fin = fopen("fin.txt", "w");
for(i=0;i<MAX/2;i++)
{
fprintf(fin, "%d", *(arr+i));
}
fclose(fin);
}
int main(void)
{
FILE *arvud;
arvud = fopen("arvud.txt", "r");
int *arr1 = sisse(arvud);
fclose(arvud);
int *arr2 = arvut(arr1);
faili(arr2);
return 0;
}
File added
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
Andmefaili lugemis yl
*/
void sisse(FILE *andmed);
int main(void)
{
FILE *andmed;
andmed = fopen("andmed.txt", "r");
sisse(andmed);
fclose(andmed);
return 0;
}
void sisse(FILE *andmed)
{
char *nimi;
float raha[100];
int kood[100];
int i = 0;
int pikkus;
FILE *tulemus;
while(!feof(andmed))
{
fscanf(andmed, "%s %lf %d\n", *(nimi+i), &raha[i], &kood[i]);
i++;
}
pikkus = i-1;
tulemus = fopen("tulemused.txt", "w");
for(i=0;i<pikkus;i++)
{
if (kood[i] == 1 || raha[i] > 50)
{
fprintf(tulemus, "%s %lf %d\n", *(nimi+i), raha[i], kood[i]);
}
}
fclose(tulemus);
}
Karl 22.5 00
Teet 34.5 01
Siim 125.7 01
Kertu -325.6 01
Kai 174 01
Timo 444 00
Lucifer 666 11
Allah 555.9 25
Kalle 123453.53 01
Mai 55.23 41
Tiina 154 55
Urve 1035 44
Peet 22.5 00
Teet 34.5 01
Erki 125.7 01
Nool -325.6 01
Vai 174 01
Tigo 444 00
Stiffler 0.01 11
Allah 555.9 25
Mai 55.23 -41
Tiina 154 55
Urve 1055535 44
Sepo -52.63 01
Kaspar 23.52 01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment