I want to make a list reading the input and i want to print the list after filling it.
I try hard but i can achieve it because i get faults.
This is my list
Code:
struct AkeraiosStruct {
int Value;
AkeraiosStruct * next;
} AkeraiosStruct;
void readinglist (AkeraiosStruct * r){
int i;
r= malloc (sizeof(struct AkeraiosStruct));
r->next=NULL;
do{
i=getchar();
insert_at_end (&r, i);
}while(i!=' ');
}
void insert_at_end (AkeraiosStruct ** ptraddr, int v)
/* Insert v as last element of list *ptraddr */
{ while (*ptraddr != NULL) /* Go to end of list */
ptraddr = &((*ptraddr)->next);/* Prepare what we need to change */
*ptraddr = malloc(sizeof(struct AkeraiosStruct)); /* Space for new node */
(*ptraddr)->Value = v; /* Put value */
(*ptraddr)->next = NULL; /* There is no next element */
}
void print(AkeraiosStruct * r) /* Print elements of list */
{ while (r != NULL) { /* Visit list elements up to the end */
printf("%d --> ", r->Value); /* Print current element */
r = r->next; /* Go to next element */
}
printf("NULL\n"); /* Print end of list */
}
int main (void){
AkeraiosStruct * A;
printf("Give the First number and put space at the end\n\n");
A=NULL;
readinglist (A);
print(A);
return 0;
}
I can debugg it.