Skip to content

Instantly share code, notes, and snippets.

@paunstefan paunstefan/creare_fisier.c
Last active Apr 20, 2017

Embed
What would you like to do?
// Creeaza fisierul binar
#include<stdio.h>
#include<conio.h>
typedef struct{
unsigned int an;
unsigned char luna;
unsigned char zi;
}DATA;
typedef struct{
char nume[20];
char cnp[14];
DATA d;
unsigned int nrm;
char fac[6];
unsigned char an;
unsigned int grupa;
char s;
char spec[11];
char note[20];
}STUDENT;
void main()
{
FILE* f;
STUDENT x;
char numef[20];
int i;
printf("Nume fisier: "); gets(numef);
f = fopen(numef, "wb");
if (!f)
printf("\nNu se poate deschide fisierul %s", numef);
else
{
for (i = 0; i < 20; i++)
x.note[i] = 0;
printf("Nume si prenume: "); gets(x.nume);
while (!feof(stdin))
{
printf("CNP: "); fflush(stdin); gets(x.cnp);
printf("Data nasterii: \n");
printf("An: "); scanf("%d", &x.d.an);
printf("Luna:"); scanf("%d", &x.d.luna);
printf("Zi: "); scanf("%d", &x.d.zi);
printf("Nr. matricol:"); scanf("%d", &x.nrm);
printf("Facutate: "); fflush(stdin); gets(x.fac);
printf("An de studiu: "); scanf("%d", &x.an);
printf("Grupa: "); scanf("%d", &x.grupa);
printf("Serie: "); fflush(stdin); scanf("%c", &x.s);
printf("Specializare: "); fflush(stdin); gets(x.spec);
fwrite(&x, sizeof(STUDENT), 1, f);
printf("Nume si prenume (sau CTRL+Z): "); fflush(stdin); gets(x.nume);
}
fclose(f);
}
printf("Gata, apasa o tasta...");
_getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.