I have this list and I'm writing a function to ask the user to add the info:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXTAB 40
#define MAXSTR 25
typedef enum {Prob, Impr, Terr, Jail} Type;
typedef struct {
int pos;
char name[MAXSTR+1];
char owner[MAXSTR+1];
int price;
Type info;
} Casella;
struct lista {
Casella Tab;
struct lista *node;
};
typedef struct lista Lista;
void printElement (Lista *);
void printTab (Lista *);
Lista * initializeTab (Lista *, int);
Lista * addInfo (Lista*);
int main()
{
Lista *list = NULL;
int i;
for (i=0; i<MAXTAB; i++){
list = initializeTab(list, i);
}
printTab(list);
return 0;
}
void printElement (Lista *l){
printf("Position: %d\n", l->Tab.pos);
}
void printTab (Lista *l){
while(l!=NULL){
printElement(l);
l=l->node;
}
}
Lista * initializeTab (Lista *l, int x){
Lista *newTab = NULL;
newTab = (Lista*)malloc(sizeof(Lista));
newTab->Tab.pos = x;
newTab->node = l;
return newTab;
}
Lista * addInfo (Lista *l){
Lista *list = NULL;
list->Tab.name = (char*)malloc(MAXSTR * sizeof(char));
return list;
}`
In the function "addInfo", I try to allocate memory for the Tab name, but it tells me I can't assign type array char to that. My question is, how do I allocate memory for various list elements? Like I want to allocate memory for the list.name, then list.owner, list.pos etc... and then assign values to them.