伊莉部落格、伊莉交友、伊莉聊天、伊莉相簿
可以幫我偵錯一下嗎
可以幫我看哪裡有錯嗎?
該怎麼改呢?
感激不盡~
#include <stdio.h>
void main(void) {
struct dnode{
struct studscore{
char *name;
char *number;
char sex;
int score;
}s;
struct dnode *LLINK, *RLINK; }
*head, *tail, *tmp, *temp;
/* insert data */
tmp = (struct dnode *) malloc(sizeof(struct dnode));
tmp->LLINK = tmp->RLINK = NULL;
tmp->s.name = (char *) malloc(3*sizeof(char));
strcpy(tmp->s.name, "鐘央");
tmp->s.number = (char *) malloc(4*sizeof(char));
strcpy(tmp->s.number, "S01");
tmp->s.sex = 'M';
tmp->s.score = 100;
head = tail = tmp;
/* 插前面 */
tmp = (struct dnode *) malloc(sizeof(struct dnode));
tmp->LLINK = NULL;
tmp->RLINK = head;
head->LLINK = tmp;
head = tmp;
tmp->s.name = (char *) malloc(3*sizeof(char));
strcpy(tmp->s.name, "錢面");
tmp->s.number = (char *) malloc(4*sizeof(char));
strcpy(tmp->s.number, "S02");
tmp->s.sex = 'F';
tmp->s.score = 99;
/* 插後面 */
tmp = (struct dnode *) malloc(sizeof(struct dnode));
tail->RLINK = tmp;
tmp->LLINK = tail;
tmp->RLINK = NULL;
tail = tmp;
tmp->s.name = (char *) malloc(3*sizeof(char));
strcpy(tmp->s.name, "候面");
tmp->s.number = (char *) malloc(4*sizeof(char));
strcpy(tmp->s.number, "S03");
tmp->s.sex = 'F';
tmp->s.score = 99;
/* 插在'鐘央'之前面 */
temp = head;
while (temp) {
if (!strcmp(temp->s.name, "鐘央")) break;
temp = temp->RLINK;
}
tmp = (struct dnode *) malloc(sizeof(struct dnode));
tmp->LLINK = NULL;
tmp->RLINK = temp;
head->LLINK = tmp;
head = tmp;
tmp->s.name = (char *) malloc(3*sizeof(char));
strcpy(tmp->s.name, "鐘前");
tmp->s.number = (char *) malloc(4*sizeof(char));
strcpy(tmp->s.number, "S02");
tmp->s.sex = 'M';
tmp->s.score = 69;
/* 插在'鐘央'之後面 */
tmp = (struct dnode *) malloc(sizeof(struct dnode));
tail->RLINK = tmp;
tmp->LLINK = tail;
tmp->RLINK = NULL;
tail = tmp;
tmp->s.name = (char *) malloc(3*sizeof(char));
strcpy(tmp->s.name, "鐘後");
tmp->s.number = (char *) malloc(4*sizeof(char));
strcpy(tmp->s.number, "S03");
tm [color=blue][size=2][ [u]瀏覽完整內容請先註冊或登入會員[/u]。][/size][/color]
|