求下面问题的C语言代码

要求:输入一组题目存入链表中,(用结构体)
输入形式:数组的大小n,题目信息
输出形式:打印所有题目
测试用例:
输入:2
1 0 3+2
1 1 10+15
输出:1 0 3+2
1 0 10+15

img


#include <stdio.h>
#include <string.h>

struct node
{
    char s[50];
    struct node *pNext;
};

void main()
{
    struct node *pHead = NULL, *pEnd = NULL, *pNode = NULL;
    int i = 1,n;
    char str[50],ch;
    scanf("%d",&n);
    for(i=0; i<=n; i++)
    {
        pNode = (struct node *)malloc(sizeof(struct node));
        if(pNode != NULL)
        {
            gets(str);
            strcpy(pNode -> s,str);
            //puts(pNode -> s);
            pNode -> pNext = NULL;
            if(pHead == NULL)
            {
                pHead = pNode;
                pEnd = pNode;
            }
            else
            {
                pEnd -> pNext = pNode;
                pEnd = pNode;
            }//end of if(pHead == NULL)
        }//end of if(pNode != NULL)


    }
    pNode = pHead;
    while(pNode != NULL)
    {
        printf("%s\n", pNode -> s);
        pHead = pNode;
        pNode = pNode -> pNext;
        free(pHead);
    }
    printf("\n");
}

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632