This is what I am trying to do:
I have been working on code that I have create a structure (hard coded in main) Then I want to malloc space for two structs (tryin to use functions). Then copy all the data in the first struct to the second struct and print the new structure.
The errors the occur is:
I don’t understand what this error means.
pointer.c:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
pointer.c:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
#include <stdio.h>
#include <stdlib.h>
#include "pointer.h"
int rec = 0;
line 7
struct emp *create(int record){
emp *new_employees = malloc(sizeof(info) * (record+1));
return new_employees;
}
line 13
struct emp *copy(emp *data, int record){
emp *new_employee = create(record+1);
int i;
for(i = 0; i<record;i++){
new_employee.first = data.first;
new_employee.last = data.last;
new_employee.start_date = data.start_date;
new_employess.sal = data.sal;
data++;
}
return new_employee;
}
int main(void){
struct info employees;
employees.first = "FIRST";
employees.last = "LAST";
employees.start_date = "June-20th-2006";
employees.sal = 55555.55;
rec = rec+1;
}
header file:
#include <string.h>
struct info {
char *first;
char *last;
char *start_date;
float sal;
} emp;
infois not a type, andempis just a variable of typestruct info. Either add a typedef (if you want toempas a type):…or add a
structkeyword.