#include<stdio.h>
typedef struct {
char floare[40];
char culoare[30];
float pret;
int codf;
}FLOARE;
void creare_fisier(char*nume) {
FILE*g;
FLOARE f;
fopen_s(&g, nume, "wb");
if (!g)
printf("Eroare");
else
{
printf("Cod floare:"); scanf_s("%d", &f.codf);
while (!feof(stdin)) {
getchar();
printf("Nume floare:"); gets(f.floare);
printf("Culoare floare:"); gets(f.culoare);
printf("Pret:"); scanf_s("%f", &f.pret);
fwrite(&f, sizeof(FLOARE), 1, g);
printf("Cod floare:"); scanf_s("%d", &f.codf);
}
fclose(g);
}
}
void afisare_fisier(char*nume) {
FILE*h;
FLOARE f;
fopen_s(&h, "lista.dat", "rb");
if (!h)
printf("Eroare");
else {
FILE*g;
fopen_s(&g, nume, "w");
fread(&f, sizeof(FLOARE), 1, g);
while (!feof(h)) {
fprintf(g, "%d %s %s %f", f.codf, f.floare, f.culoare, f.pret);
fread(&f, sizeof(FLOARE), 1, g);
}
fclose(g), fclose(h);
}
}
void main() {
char numef[] = "lista.dat";
creare_fisier(numef);
char numetxt[] = "raport.txt";
afisare_fisier(numetxt);
}
The subprogram which creates the binary file is working, but the listing of the information into a text file is not working. When I run the code it's not happening anything and the space occupied by the text file is growing as I keep open the console. I don't really have experience with the subprograms, but I know the structure of listing into a text file.
This is for a homework task.