The following code shows that format '%s' expects argument of type 'char *', but line 139 has type 'int'. I don't see any mistakes in variable types. This issue is present at the scanf. Along with this issue there are 3 more related ones. I keep trying and getting this very same error. I ask if someone can please kindly assist?
This is the struct:
struct employee
{
char name[50];
char sex;
char adrs[50];
char dsgn[25];
int age,empID;
float slry;
};
This is the entire code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <stdbool.h>
#include <windows.h>
#include "struct.h"
void insert();
void list();
void edit();
void del();
void ext();
FILE * fptr, *ftemp;
struct employee e;
long int recsize;
char empname[50];
int main()
{
//FILE * fptr, *ft;
int choice;
//fptr = fopen("ems.txt","rb+");
fptr = fopen("ems.txt", "r+");
if (fptr == NULL)
{
printf("Can't find file! Attempting to create file...
");
fptr = fopen("ems.txt","w+");
if(fptr == NULL)
{
printf("Can't create file. Exiting...");
ext(1);
}
}
//Explain the reason for this?
//recsize = (long int) sizeof(e);//
while(1)
{
printf("*******************************
");
printf("
Employee management system");
printf("
1. Insert employee information");
printf("
2. List all employee information");
printf("
3. Edit employee information");
printf("
4. Delete employee information");
printf("
5. Exit");
printf("
*****************************
");
printf("
Enter your choice: ");
scanf("%d", &choice);
fflush(stdin);
switch(choice)
{
case 1:
puts("Insert was chosen");
insert();
break;
case 2:
puts("List was chosen");
list();
break;
case 3:
puts("Edit was chosen");
edit();
break;
case 4:
puts("Delete was chosen");
del();
break;
case 5:
puts("Exit was chosen");
ext(1);
break;
default:
puts("Choice is incorrect!!");
continue;
}
}
return 0;
}
void insert()
{
char next;
do
{
printf("**********************************************************
");
printf("
Enter the name of the employee: ");
gets(e.name);
printf("
Enter the sex of the employee (M/m or F/f): ");
gets(&e.sex);
printf("
Enter the address of the employee: ");
gets(e.adrs);
printf("
Enter designation of the employee: ");
gets(e.dsgn);
printf("
Enter age of the employee: ");
scanf("%d", &e.age);
printf("
Enter basic salary of the employee: ");
scanf("%f", &e.slry);
printf("
Enter the employee's ID: ");
scanf("%d", &e.empID);
fputs(e.name, fptr);
fputs(&e.sex, fptr);
fputs(e.adrs, fptr);
fputs(e.dsgn, fptr);
fprintf(fptr, "%d
%f
%d
", e.age, e.slry, e.empID);
// fwrite(&e,recsize,1,fptr);
fflush(stdin);
printf("
Do you want to input more? (y/n): ");
next = getche();
printf("
");
}
while(next !='n');
fclose(fptr);
}
void list ()
{
/* what is going on here??? */
while(fread(&e,recsize,1,fptr)==1)
{
printf("
%s %s %s %s %d %.2f %d",e.name,e.sex,e.adrs,e.dsgn,e.age,e.slry,e.empID);
}
getche();
return ;
}
void edit ()
{
char next;
do
{
printf("Enter the employee name to be edited: ");
scanf("%s", empname);
while(fread(&e,recsize,1,fptr)==1)
{
if(strcmp(e.name,empname) == 0)
{
printf("
Enter new name,sex,address,designation,age,salary,employee ID ");
scanf("%s %s %s %s %d %.2f %d",e.name,e.sex,e.adrs,e.dsgn,&e.age,&e.slry,&e.empID);
fseek(fptr,-recsize,SEEK_CUR);
fwrite(&e,recsize,1,fptr);
break;
}
}
printf("
Edit another record(y/n)");
next = getche();
fflush(stdin);
}
while(next != 'n');
return ;
}
void del()
{
char next;
do
{
printf("
Enter name of employee to delete: ");
scanf("%s",empname);
ftemp = fopen("Temp.dat","wb");
while(fread(&e,recsize,1,fptr) == 1)
{
if(strcmp(e.name,empname) != 0)
{
fwrite(&e,recsize,1,ftemp);
}
}
fclose(fptr);
fclose(ftemp);
remove("ems.txt");
rename("Temp.dat","ems.txt");
fptr = fopen("ems.txt", "rb+");
printf("Delete another record(y/n)");
fflush(stdin);
next = getche();
}while(next !='n');
}
See Question&Answers more detail:
os