Commit 12d806ae by trkall

Esimene kodut66

parent d84c90a9
asf Kala 12
assdf Kala 12
fgs Loom 13
gsa Lind 13
sal Putukas 83
gsa Lind 132
sal Putukas 835
fasgs Loom 132
asgsa Lind 13
assal Putukas 832
fgs Loom 13
asf Kala 12
assdf Kala 12
......@@ -3,12 +3,12 @@
#include <string.h>
#include "functions.c"
typedef struct // https://www.tutorialspoint.com/cprogramming/c_structures.htm
/*typedef struct // https://www.tutorialspoint.com/cprogramming/c_structures.htm
{
char Nimi[50];
char Liik[50];
int Vanus;
}Ryhm;
}Ryhm;*/
......@@ -34,24 +34,27 @@ int main(void)
{
FILE *F1;
FILE *F2;
F2 = fopen("F2.txt", "w");//tyhendab faili
fclose(F2);
int i=0;
int pikkus;
char *str1 = "Loom";
char *str2 = "Lind";
char *str3 = "Kala";
char *str4 = "Putukas";
Ryhm *n = (Ryhm*)malloc(sizeof(Ryhm)); // http://stackoverflow.com/questions/11280523/c-reading-from-file-into-structure
//Ryhm *n = (Ryhm*)malloc(sizeof(Ryhm));
Ryhm *n = malloc(1000000); // http://stackoverflow.com/questions/11280523/c-reading-from-file-into-structure
F1 = fopen("F1.txt", "r");
//n = (Ryhm*)malloc(sizeof(Ryhm));
while(!feof(F1))
{
n = (Ryhm*)realloc(n, 35);
n = (Ryhm*)realloc(n, 350);
fscanf(F1,"%s %s %d", (n+i)->Nimi, (n+i)->Liik, &(n+i)->Vanus);
printf("%s %s %d", (n+i)->Nimi, (n+i)->Liik, (n+i)->Vanus);
i++;
}
i=0;
i--;
printf("-%s-%s-%d-", (n+i)->Nimi, (n+i)->Liik, (n+i)->Vanus);
pikkus = i;
fclose(F1);
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "functions.c"
int main(void)
{
FILE *F1;
FILE *F2;
F2 = fopen("F2.txt", "w");//tyhendab faili
fclose(F2);
int i=0;
int pikkus;
char *str1 = "Loom";
char *str2 = "Lind";
char *str3 = "Kala";
char *str4 = "Putukas";
Ryhm *n = malloc(100000);
F1 = fopen("F1.txt", "r");
while(!feof(F1))
{
n = (Ryhm*)realloc(n, 350);
fscanf(F1,"%s %s %d", (n+i)->Nimi, (n+i)->Liik, &(n+i)->Vanus);
i++;
}
pikkus = i-1;
fclose(F1);
faili_lugemine(pikkus, str1, F2, n);
faili_lugemine(pikkus, str2, F2, n);
faili_lugemine(pikkus, str3, F2, n);
faili_lugemine(pikkus, str4, F2, n);
return 0;
}
#include <stdio.h>
typedef struct // https://www.tutorialspoint.com/cprogramming/c_structures.htm
{
char Nimi[50];
char Liik[50];
int Vanus;
}Ryhm;
void faili_lugemine(int pikkus, char *str, FILE *F2, Ryhm *n)
{
F2 = fopen("F2.txt", "a");
......
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