Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include<stdio.h>
#include<conio.h>
#define NOGRADEYET 0
#define ABSENT -1
typedef struct {
unsigned int nrm;
char nume[30];
unsigned char ans;
unsigned int grupa;
char fac[6];
char note[20];
unsigned char is;
}STUDENT;
void main(){
FILE* f;
STUDENT x;
int nrart, cheie, a, i;
char numefr[20] = "..\\SR.dat";
f = fopen(numefr, "wb+");
if (!f)
printf("\nNu se poate deschide fisierul %s", numefr);
else
{
printf("\nNumar matricol: "); scanf("%d", &cheie);
while (!feof(stdin)) //while(cheie != -1)
{
fseek(f, 0, 2);
nrart = ftell(f) / sizeof(STUDENT);
if (cheie >= nrart)
{
x.is = 0;
for (i = nrart; i <= cheie; i++)
fwrite(&x, sizeof(STUDENT), 1, f);
}
fseek(f, cheie*sizeof(STUDENT), 0);
fread(&x, sizeof(STUDENT), 1, f);
if (x.is == 1)
printf("\nCheie duplicata: %d", cheie);
else
{
printf("\nNume si prenume: "); fflush(stdin); gets(x.nume);
printf("An de studiu "); scanf("%d", &a); x.ans = a;
printf("Grupa: "); scanf("%d", &x.grupa);
printf("Facultate (max 5): "); fflush(stdin); gets(x.fac);
for (i = 0; i < 20; i++)
x.note[i] = NOGRADEYET;
x.nrm = cheie;
x.is = 1;
fseek(f, cheie*sizeof(STUDENT), 0);
fwrite(&x, sizeof(STUDENT), 1, f);
}
printf("\nNumar matricol: "); scanf("%d", &cheie);
}
fclose(f);
printf("\n\nAm creat fisieul relativ %s", numefr);
}
printf("\n\nGata, 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.