#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
struct Employee
{
int id;
char name[20];
char position[20];
int salary;
int dateofjoin;
char address[20];
};
int main()
{
struct Employee a[5], b[5];
FILE* fptr;
int i;
fptr = fopen("file.txt", "wb");
for (i = 0; i < 3; ++i)
{
fflush(stdin);
printf("\nEnter ID: ");
scanf("%d", &a[i].id);
printf("\nEnter name: ");
scanf("%s",&a[i].name);
printf("\nEnter Position/Designation: ");
scanf("%s",&a[i].position);
printf("\nEnter Salary: ");
scanf("%d", a[i].salary);
printf("\nEnter DateOfJoining: ");
scanf("%d", a[i].dateofjoin);
printf("Enter Address: ");
scanf("%s",&a[i].address);
}
fwrite(a, sizeof(a), 1, fptr);
fclose(fptr);
fptr = fopen("file.txt", "rb");
fread(b, sizeof(b), 1, fptr);
for (i = 0; i < 3; ++i)
{
printf("\nID: %d \tName: %s \tPosition/Designation: %s Salary: %d\tDateOfJoining: %d\tAddress: %s", b[i].id, b[i].name, b[i].position, b[i].salary, b[i].dateofjoin,
b[i].address);
}
fclose(fptr);
}
My program always crash after giving salary input, I even tried #define _CRT_SECURE_NO_WARNINGS, to avoid error but it is of no use. hope I'll get my problem solved soon, please do explain when you reply as it is sort of assignment for me
In your scanf("%d", a[i].salary);
& is missing before a[i].salary
User contributions licensed under CC BY-SA 3.0