I have an important project for uni in binary files in C. I have to put information in a relative binary file and it keeps showing me this "A breakpoint instruction (__debugbreak() statement or a similar call) was executed in tema.exe.", in the debugger.
What can I do?
This is the code
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
typedef struct {
int id;
int EsteSetat;
char nume[100];
int varsta;
double salariu;
char telefon[30];
}Angajat;
int articole(FILE* f, int lgart) // lgart este lungimea unui articol
{
int pozp;
int nrart;
pozp = ftell(f); //memoreaza pozitia curenta a pointerului in fisier
fseek(f, 0, 2);
nrart = ftell(f) / lgart;
fseek(f, pozp, 0);
return nrart;
}
void scriere(FILE* f)
{
int id;
Angajat a;
printf("Introduceti ID angajat: ");
scanf("%d", &id);
while (!feof(stdin))
{
if (id >= articole(f, sizeof(Angajat)))
{
a.EsteSetat = 0;
fseek(f, 0, 2);
for (int i = articole(f, sizeof(Angajat)); i <= id; i++)
{
fwrite(&a, sizeof(Angajat), 1, f);
}
}
fseek(f, id * sizeof(Angajat), 0);
fread(&a, sizeof(Angajat), 1, f);
if (a.EsteSetat == 1)
printf("Angajatul deja exista");
else if (a.EsteSetat == 0)
{
a.EsteSetat = 1;
a.id = id;
printf("Introduceti numele angajatului: "); getchar(); gets(a.nume);
printf("Varsta: "); scanf("%d", &a.varsta);
printf("Salariu: "); scanf("%d", &a.salariu);
printf("Telefon: "); scanf("%s", a.telefon);
fseek(f, ftell(f) - sizeof(Angajat), 0);
fwrite(&a, sizeof(Angajat), 1, f);
}
printf("Introduceti alt ID sau CTRL-Z+ENTER de 3 ori pt a iesi din fisier: "); scanf("%d", &id);
}
}
int main()
{
char numef[20];
printf("Introduceti numele fisierului: ");
scanf("%s", &numef);
FILE* f = fopen(numef, "rb+");
Angajat a;
scriere(f);
fclose(f);
return 0;
}
thank you!