When I try to compile the code down below the executable does not open. I also tried debugging and I got this error in the printf of viewNode line: Failed to execute MI command: -data-evaluate-expression (l)->info Error message from debugger back end: Cannot access memory at address 0xeb
Now, I understand that I'm trying to access memory location that I shouldn't, but where's the problem?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct char_node *char_list;
struct char_node{
char info;
char_list next;
}char_node;
char_list makesNode(void);
char_list makesValueNode(char value);
char_list makesList(char_list l, char nome[]);
void viewNode(char_list l);
void viewList(char_list l);
int main(){
char_list nuovo;
char nome[] = "Ugo";
makesList(nuovo, nome);
if(nuovo != NULL)
viewList(nuovo);
return 0;
}
char_list makesNode(void){
return (char_list)malloc(sizeof(struct char_node));
}
char_list makesValueNode(char value){
char_list li = NULL;
li = makesNode();
li -> info = value;
li -> next = NULL;
return li;
}
char_list makesList(char_list nuovo, char nome[]){
char_list head = NULL;
int l = strlen(nome);
l = l - 1;
while(l >= 0 ){
nuovo = makesValueNode(nome[l]);
if(nuovo != NULL){
nuovo -> next = head;
head = nuovo;
l = l - 1;
}
}
return nuovo;
}
void viewNode(char_list l){
printf("%c", l->info);
}
void viewList(char_list l){
while(l != NULL){
viewNode(l);
l = l -> next;
}
}