S
shellcode
i wrote this liked lists test program. it works, but im just wonderding
if i did everything relating to NULL and memory allocation correctly or
if i missed out on some important checks. thank's
--------single.c---------
#include <stdlib.h>
#include <stdio.h>
struct node {
int data;
struct node* next;
};
struct node* addtotail(struct node* head, int num);
void printlist(struct node* head);
int main()
{
struct node* head;
int i;
head = malloc(sizeof(struct node));
for(i = 0; i <= 100; i++)
{
addtotail(head, i);
}
printlist(head);
return 0;
}
struct node* addtotail(struct node* head, int num)
{
struct node* current;
struct node* newnode;
newnode = malloc(sizeof(struct node));
newnode->data = num;
newnode->next = NULL;
current = head;
while (current->next != NULL)
current=current->next;
current->next = newnode;
return current->next;
}
void printlist(struct node* head)
{
struct node* current;
current = head;
while (current->next != NULL)
{
current=current->next;
printf("%d\n", current->data);
}
}
----------eof----------
if i did everything relating to NULL and memory allocation correctly or
if i missed out on some important checks. thank's
--------single.c---------
#include <stdlib.h>
#include <stdio.h>
struct node {
int data;
struct node* next;
};
struct node* addtotail(struct node* head, int num);
void printlist(struct node* head);
int main()
{
struct node* head;
int i;
head = malloc(sizeof(struct node));
for(i = 0; i <= 100; i++)
{
addtotail(head, i);
}
printlist(head);
return 0;
}
struct node* addtotail(struct node* head, int num)
{
struct node* current;
struct node* newnode;
newnode = malloc(sizeof(struct node));
newnode->data = num;
newnode->next = NULL;
current = head;
while (current->next != NULL)
current=current->next;
current->next = newnode;
return current->next;
}
void printlist(struct node* head)
{
struct node* current;
current = head;
while (current->next != NULL)
{
current=current->next;
printf("%d\n", current->data);
}
}
----------eof----------