[ create a new paste ] login | about

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

C, pasted on Nov 29:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct student{
	char name[31];
	int math;
	int eng;
	struct student *next;
	struct student *prev;
};

int main(void){
	struct student *st_a, *st_b, *st_c;
	struct student *st_first;
	struct student *st_p;

	st_a = (struct student *)malloc(sizeof(struct student));
	st_b = (struct student *)malloc(sizeof(struct student));
	st_c = (struct student *)malloc(sizeof(struct student));

	strcpy(st_a->name,"Yamada");
	st_a->math = 86;
	st_a->eng = 74;

	strcpy(st_b->name,"Suzuki");
	st_b->math = 81;
	st_b->eng = 92;

	strcpy(st_c->name,"Tanaka");
	st_c->math = 54;
	st_c->eng = 63;

	st_first = st_a;
        st_a->next = st_b;
        st_b->next = st_c;
        st_c->next = NULL;

        st_a->prev = NULL; 
        st_b->next = st_a; 
        st_c->next = st_c; 

        st_b->prev->next = st_b->next; 
        st_b->next->prev = st_b->prev; 
        free(st_b); 
	
	for(st_p = st_first ; st_p != NULL ; st_p = st_p -> next)
		printf("%sの数学の点は%d点、英語の点は%d点\n",st_p->name,st_p->math,st_p->eng);

	return 0;
}


Output:
1
Segmentation fault


Create a new paste based on this one


Comments: