error 2440 and 2068

I keep getting these errors and I can't figure out how to fix it. The errors are at line 17 and 20.
code:

#include <stdafx.h>
#include <stdlib.h>

typedef struct
{
int number;
int department;
float rate;
char exempt;
int hours;
} Employee;

Employee *file_read_employee (FILE *f)
{
// fprintf (stderr, "I\'m inside %s (%p);\n", __func__, f);

Employee *e = malloc (sizeof(Employee));
if (!e)
{
perror (__func__);
exit (EXIT_FAILURE);
}

if (fscanf (f, "%d %d %f %c %d\n", &e->number, &e->department, &e->rate, &e->exempt, &e->hours) != 5)
{
free (e);
return NULL;
}

return e;
}

int main (int argc, char**argv)
{
if (argc<2)
{
fprintf (stderr, "Which file I should read?\n");
return EXIT_FAILURE;
}

FILE *f = fopen (argv[1],"r");
if (!f)
{
perror (argv[1]);
return EXIT_FAILURE;
}

printf ("Enter the employee's number: ");
int number;
scanf ("%d%*c", &number);
printf ("Employee\'s number: %d\n", number);

Employee *e;
while ( (e = file_read_employee (f)) && (e->number!=number) );
if (!e)
{
fprintf (stderr, "There is no such employee.\n");
return EXIT_SUCCESS;
}
printf ("Deparment: %d\nPay rate: %f\nExempt: %c\nHours worked: %d\nBase pay: %f\n",
e->department, e->rate, e->exempt, e->hours, e->rate*(float)e->hours);
return EXIT_SUCCESS;
}


This is what the errors say:

cpp(17) : error C2440: 'initializing' : cannot convert from 'void *' to 'Employee *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast

cpp(20) : error C2065: '__func__' : undeclared identifier

I understand what it says, I just don't know how to fix it.
Employee *e = malloc (sizeof(Employee));

malloc returns a void*. You are storing the result in an Employee*.
The compiler cannot (will not) implicitly convert the void* return value of malloc
to an Employee*. You have to explicitly cast it.


__func__ is undefined. I don't know what the symbol is in microsoft
land, but for gcc it is __FUNCTION__ or __PRETTY_FUNCTION__.
ok, I got that 2nd error cleared up but I don't understand fully what you are saying about the first error and how to fix it.
Topic archived. No new replies allowed.