I am writing a program in C. The following is an extract from my code:
Code:
enum coin_types
{
FIVE_CENTS=5,
TEN_CENTS=10,
TWENTY_CENTS=20,
FIFTY_CENTS=50,
ONE_DOLLAR=100,
TWO_DOLLARS=200
};
struct coin
{
enum coin_types denomination;
unsigned count;
};
void * safe_malloc(size_t size)
{
void * mem = malloc(size);
if(!mem)
{
perror("Failed to allocate memory");
abort();
}
return mem;
}
FILE * coinsf = NULL;
char line[600];
coinsf = fopen(coinsfile, "r");
/* Read in each line, while line is not null */
while(fgets(line, 600, coinsf) != NULL)
{
struct coin * new;
line[strlen(line)-1] = 0;
new = new_coins_data_line(line);
}
/* this function is in another file */
struct coin new_coins_data_line(char * line)
{
struct coin * newdata = NULL;
newdata = (struct coin *)
safe_malloc(sizeof(struct coin));
return newdata;
}
I'm getting the following errors:
For: new = new_coins_data_line(line);
"Incompatible types in assignment"
For: return newdata;
"Incompatible types in return"
There seem to be problems with my variables and perhaps it is related to the type 'struct coin' which has an enumerated type within it.
Please help me fix these errors. Thank you.