X
Xarky
Hi,
I am writing a linked list in the following way.
struct list
{
struct list *next;
char *mybuff;
};
struct list *myList = NULL;
struct list *endList = NULL;
void getline(char s[], int lim)
{
int c, i;
for(i=0; ((i<lim-1) && ((c=getchar()) != '\n')); i++)
s = c;
s ='\0';
} // end method getline
void add_item(char *data)
{
if (!endList)
{
endList = (struct list *)malloc(sizeof(struct list));
myList = endList;
endList->mybuff = data;
endList->next = NULL;
} // end if
else
{
endList->next = (struct list *)malloc(sizeof(struct list));
endList = endList>next;
endList->mybuff = data;
endList->next = NULL;
} // end else
}
void printList()
{
struct list *current = myList;
while(current)
{
printf("%s\n", current->mybuff);
current = current->next;
}
}
int main()
{
char buff[50];
// called for a n times
getline(buff, 50);
add_item(buff);
printList();
}
Now in the printList method, the nothing is being printed, but just a
simple blank line for each item.
Can someone help me solve this problem out.
Thanks in Advance
I am writing a linked list in the following way.
struct list
{
struct list *next;
char *mybuff;
};
struct list *myList = NULL;
struct list *endList = NULL;
void getline(char s[], int lim)
{
int c, i;
for(i=0; ((i<lim-1) && ((c=getchar()) != '\n')); i++)
s = c;
s ='\0';
} // end method getline
void add_item(char *data)
{
if (!endList)
{
endList = (struct list *)malloc(sizeof(struct list));
myList = endList;
endList->mybuff = data;
endList->next = NULL;
} // end if
else
{
endList->next = (struct list *)malloc(sizeof(struct list));
endList = endList>next;
endList->mybuff = data;
endList->next = NULL;
} // end else
}
void printList()
{
struct list *current = myList;
while(current)
{
printf("%s\n", current->mybuff);
current = current->next;
}
}
int main()
{
char buff[50];
// called for a n times
getline(buff, 50);
add_item(buff);
printList();
}
Now in the printList method, the nothing is being printed, but just a
simple blank line for each item.
Can someone help me solve this problem out.
Thanks in Advance