C语言链表有序排序问题

img


写看一个有序合并两个表的程序,结构体包括学号和名字,结果输出来是这种情况,不知道是哪里出了问题

1,建议加上括号scanf时 &(s->ID),&(s->name)
2,结构体中char name 你输入的只有一个字符吗如a 或 b
3,显示输入name时没看到你及时输入字符

修改了一下链表合并处的代码,供参考。ID和name我合起来传了,忽略

#include <stdio.h>
#include <stdlib.h>

struct circle{
    int ID;
    char name;
    struct circle* next;
};

int main() {
    struct circle* head = (struct circle*) malloc(sizeof(struct circle));
    head->next=NULL;
    struct circle* p;
    p = head;
    int n;
    printf("请输入表长:");
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        struct circle* s = (struct circle*) malloc(sizeof(struct circle));
        p->next = s;
        printf("请输入ID和name: ");
        scanf("%d %c", &s->ID, &s->name);
        s->next = NULL;
        p = s;
    }
    p = head;

    struct circle* head1 = (struct circle*) malloc(sizeof(struct circle));
    head1->next=NULL;
    struct circle* p1;
    p1 = head1;
    int k;
    printf("请输入表长:");
    scanf("%d", &k);
    for (int i = 1; i <= k; i++) {
        struct circle* s = (struct circle*) malloc(sizeof(struct circle));
        p1->next = s;
        printf("请输入ID和name: ");
        scanf("%d %c", &s->ID, &s->name);
        s->next = NULL;
        p1 = s;
    }
    p1 = head1;

    struct circle* head2 = (struct circle*) malloc(sizeof(struct circle));
    head2->next=NULL;
    struct circle* p2;
    p2 = head2;
    p = p->next;
    p1 = p1->next;

    while(p != NULL || p1 != NULL) {
        if (p1 == NULL || (p != NULL && p->ID > p1->ID)) {
            p2->next = p;
            p2 = p;
            p = p->next;
        } else {
            p2->next = p1;
            p2 = p1;
            p1 = p1->next;
        }
    }

    p2 = head2;
    printf("输出:");
    for (int i = 0; i < n+k; i++) {
        p2 = p2->next;
        printf("%d %c ", p2->ID, p2->name);
    }

}