0% found this document useful (0 votes)
29 views2 pages

#Include Typedef Struct (Int Cod Char Nume (30) Float Pret Int Cant ) CARTI

The document describes a C program that manages book activities stored in a sequentially organized binary file. It includes two functions: 1. A function called "creare" that creates a sequentially organized binary file to write book data to. It prompts the user for a file name and writes book code, name, price, and quantity to the file. 2. A function called "consultare" that reads all elements from a previously created binary file and writes them to a new text file. It prompts the user for the binary file and new text file names and copies the book data from the binary to the text file.

Uploaded by

Teodora Tudoran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

#Include Typedef Struct (Int Cod Char Nume (30) Float Pret Int Cant ) CARTI

The document describes a C program that manages book activities stored in a sequentially organized binary file. It includes two functions: 1. A function called "creare" that creates a sequentially organized binary file to write book data to. It prompts the user for a file name and writes book code, name, price, and quantity to the file. 2. A function called "consultare" that reads all elements from a previously created binary file and writes them to a new text file. It prompts the user for the binary file and new text file names and copies the book data from the binary to the text file.

Uploaded by

Teodora Tudoran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

 I.

Realizati aplicatia care sa gestioneze activitatiile,intr-un fisier


binar organizat secvential, desfasurate intr-un articol de tip
CARTI.

#include<stdio.h>
typedef struct {int cod;
char nume[30];
float pret;
int cant;} CARTI;

1.Sa se scrie subprogramul care creeaza un fisier binar organizat secvential, in


care sa vor scrie date despre carti.

void creare()
{
FILE *f; char nume[20]; CARTI p;
printf("nume fisier:"); gets(nume);
fopen_s(&f, nume, "wb");
if (!f)
printf("eroare");
else {
printf("Introduceti codul:");
scanf_s("%d", &p.cod);
while (!feof(stdin))
{
getchar();
printf("nume="); gets(p.nume);
printf("pret="); scanf_s("%f", &p.pret);
printf("cantitate="); scanf_s("%d", &p.cant);
fwrite(&p, sizeof(CARTI), 1, f);
printf("Introduceti codul:");
scanf_s("%d", &p.cod);
}
fclose(f);

}
2.Sa se scrie intr-un fisier tex,t toate elementele dintr-un fisier binar creat
anterior.

void consultare ()
{
FILE *f; char nume[20]; CARTI p;
printf("nume fisier:"); gets(nume);
fopen_s(&f, nume, "rb");
if (!f)
printf("eroare");
else {
FILE *g;
printf("Introduceti nume nou fisier:"); gets(nume);
fopen_s(&g, nume, "w");
fread(&p, sizeof(CARTI), 1, f);
while (!feof(f))
{
fprintf(g, "%d %s %f %d \n", p.cod, p.nume, p.pret, p.cant);
fread(&p, sizeof(CARTI), 1, f);
}
fclose(f);
fclose(g);
}
}

You might also like