I am having a problem operating with a char array.
My idea was to use scanf to store input in a char array and then store the contents of that array inside a struct.
Here is the code which may be easier for you to understand:
struct ListaCategoria {
int ident;
char data[MAX];
struct ListaCategoria* next;
};
struct ListaCategoria* headCat;
void inserirCat(){
int x;
char arr[MAX];
printf("Identificacao : ");
scanf("%d", &x);
printf("Designacao : ");
scanf("%c[^\n]", &arr);
struct ListaCategoria* temp = (struct ListaCategoria*) malloc(sizeof(struct ListaCategoria));
(*temp).ident = x;
(*temp).data = arr; //this is the line that's giving some trouble can someone explain me why?
}
scanf("%c[^\n]", &arr);will invoke undefined behavior in C becausechar(*)[MAX]is passed wherechar*is required.temp->dataandtemp->identwould be shorter