[ create a new paste ] login | about

Link: http://codepad.org/yhMQB6vC    [ raw code | output | fork ]

C, pasted on Jun 17:
#include<stdio.h>
#include<stdlib.h>

struct st{

  int value1;
  int value2;
  struct st *next;
};

struct st *new_st(int v1, int v2);

void free_sts(struct st *s);
void re_print_sts(struct st *s);

int main()
{
  struct st *head = NULL;
  struct st *s;

  s = new_st(-1, 1);
  s->next = head;
  head = s;

  s = new_st(-2, 12);
  s->next = head;
  head = s;

  s =  new_st(-3, 23);
  s->next = head;
  head = s;

  re_print_sts(head);

  free_sts(head);

  return 0;
}

struct st *new_st(int v1, int v2)
{
  struct st *s;

  if((s = (struct st *)malloc(sizeof(struct st))) != NULL){
    s->value1 = v1;
    s->value2 = v2;
  }

  return s;
}

void re_print_sts(struct st *s)
{

  if(s != NULL){
    printf("(%d, %d)\n",s->value1, s->value2);
    re_print_sts(s + 1);
  }
}


Output:
1
2
In function `main':
undefined reference to `free_sts'


Create a new paste based on this one


Comments: