C语言scanf报错


#include <stdio.h>
#include <malloc.h>
#define N 3
typedef struct Student 
{
    char chName[16];
    long iNumber;
    int score;
    struct Student* next;
}NODE,* NODEP;
NODEP fnCreat(void)
{
    NODEP pEnd, pNew, pHead;
    int iCount = 1;
    pHead = NULL;
    while (iCount <= N)
    {
        pNew = (NODEP)malloc(sizeof(NODE));
        if (iCount == 1)
        {
            pHead = pNew;
        }
        else
        {
            pEnd->next = pNew;
        }
        printf("输入%d个学生信息(姓名,学号,成绩):", iCount);
        scanf("%s", pNew->chName,16);
        scanf("%ld", pNew->iNumber);
        scanf("%d", pNew->score);
        pNew->next = NULL;
        pEnd = pNew;
        iCount++;
    }
    return pHead;

}
void fnPrint(NODEP pHead)
{
    int iCount = 1;
    NODEP pTemp;
    pTemp = pHead;
    printf("\t学生信息如下:\n");
    while (pTemp!=NULL)
    {
        printf("学生%d,姓名:%s,学号:%ld,成绩:%d\n",iCount,pTemp->chName,pTemp->iNumber,pTemp->score);
        pTemp = pTemp->next;
        iCount++;
    }
}
void main() 
{
    NODEP pHead;
    pHead = fnCreat();
    fnPrint(pHead);
}

这个代码不知道错哪里了
如果可以的话可以分析一下整体嘛

测试图:

img

改正如下:

 
#include <stdio.h>
#include <malloc.h>
#define N 3
typedef struct Student 
{
    char chName[16];
    long iNumber;
    int score;
    struct Student* next;
}NODE,* NODEP;
NODEP fnCreat(void)
{
    NODEP pEnd, pNew, pHead;
    int iCount = 1;
    pHead = NULL;
    while (iCount <= N)
    {
        pNew = (NODEP)malloc(sizeof(NODE));
        if (iCount == 1)
        {
            pHead = pNew;
        }
        else
        {
            pEnd->next = pNew;
        }
        printf("输入%d个学生信息(姓名,学号,成绩):", iCount);
        scanf("%s", pNew->chName);
        scanf("%ld", &pNew->iNumber);
        scanf("%d", &pNew->score);
        pNew->next = NULL;
        pEnd = pNew;
        iCount++;
    }
    return pHead;
 
}
void fnPrint(NODEP pHead)
{
    int iCount = 1;
    NODEP pTemp;
    pTemp = pHead;
    printf("\t学生信息如下:\n");
    while (pTemp!=NULL)
    {
        printf("学生%d,姓名:%s,学号:%ld,成绩:%d\n",iCount,pTemp->chName,pTemp->iNumber,pTemp->score);
        pTemp = pTemp->next;
        iCount++;
    }
}
int main() 
{
    NODEP pHead;
    pHead = fnCreat();
    fnPrint(pHead);
    return 0;
}

希望对题主有所帮助!可以的话,帮忙点个采纳!

scanf("%s", pNew->chName,16);
scanf("%ld", pNew->iNumber);
scanf("%d", pNew->score);
改为
scanf("%s", pNew->chName);
scanf("%ld", &pNew->iNumber);
scanf("%d", &pNew->score);