I am trying to create a structure that can be dynamically added to with malloc and free. There are three functions that I need to implement. I need to be able to print the current structure and move to the next structure and print it as well (Needs to loop through and print each struct).
This part give me an error that goes as follow:
No more issues occured look at what I edited. I cannot submit my own answers
Employee.c:27: warning: assignment makes integer from pointer without a cast
Line is printf(\n The Employee's name is:%s, employee->fullName);
Employee.c:29: warning: assignment makes integer from pointer without a cast
printf("\nThe Employee started on %s", employee->startdate);
Here's some of my source:
#include <stdio.h>
#include <stdlib.h>
#include "Employee1.h"
/// PRINT RECORDS ///
void printRecords(myEmployee * emp)
{
myEmployee *employee;
for (employee = emp; employee != NULL; employee = employee->next) {
printf("\nThe Employee's Name is: %s", employee->fullName);
printf("\nThe Employee makes is a year $ %f", employee->salary);
printf("\nThe Employee started on %s", employee->startdate);
printf("\n\nThe Next Employee:\n");
}
}
//// CREATERECORD ////
myEmployee *createRecord(char *fullname, char *date, float sal)
{
myEmployee *newEmployees = malloc(sizeof(myEmployee));
if (newEmployees != NULL) {
newEmployees->fullName[MAXSIZE] = fullname;
newEmployees->salary = sal;
newEmployees->startdate[MAXSIZE] = date;
newEmployees->next = NULL;
}
return newEmployees;
}
These are two of the three functions that I have implemented.
This is the header file that is included:
#include <string.h>
#define MAXSIZE 200
typedef struct employee {
char *fullName;
float salary;
char *startdate;
struct employee *next;
} myEmployee;
void printRecords(myEmployee * emp);
myEmployee *createRecord(char *fullname, char *date, float sal);
myEmployee *addRecord(char *fullname, char *date, float sal);
void deleteRecord();
Can anyone help point out what is causing the error or what it means when you have a pointer without cast and how to go about making line 32 a compatible pointer type.
Solution: In the createRecord function is deleted the "[MAXSIZE]" and the code ran with no issues