C 为什么可以';列表没有显示吗?

C 为什么可以';列表没有显示吗?,c,data-structures,linked-list,structure,C,Data Structures,Linked List,Structure,C程序要求显示初始化的列表。get3rdYear从列表P中删除所有三年级学生。所有三年级学生将被移至新列表并返回调用函数。如果课程是BSIT,则函数displayBSIT显示列表中的学生姓名。功能displayList显示列表中学生的全名。这个程序的问题是,当它运行时,没有显示初始化数据,只有黑屏显示 #include<stdio.h> #include<string.h> #include<conio.h> #include<stdlib.h>

C程序要求显示初始化的
列表
get3rdYear
从列表P中删除所有三年级学生。所有三年级学生将被移至新列表并返回调用函数。如果课程是BSIT,则函数
displayBSIT
显示列表中的学生姓名。功能
displayList
显示列表中学生的全名。这个程序的问题是,当它运行时,没有显示初始化数据,只有黑屏显示

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

typedef struct {
    char fName[16];
    char lName[16];
    char mI;
}Name;
typedef struct{
    int id;
    Name fullName;
    char course[20];
    int yrlvl;
}Record;

typedef struct node{
    Record student;
    struct node *link;
}*List;

void initList(List *P);

//create the following functions:
List get3rdYear(List *P);
void displayBSIT(List P);
void displayList(List P);
/*
    get3rdYear-> removes all the students with the year level 3 from List P.
        All the 3 year students will be moved to a new List and returned to the 
        calling function.
    displayBSIT-> displays the student name from the list if the course is BSIT
    displayList-> display the full name of the students in the list
*/

int main(void){
    List L, thirdYear;
    initList(&L);
    displayBSIT(L);
    //thirdYear = get3rdYear(&L);
    displayList(L);
    //displayList(thirdYear);
    //initalize L by calling initList()
    //call displayBSIT()
    //call get3rdYear(), thirdYear will recieve the list returned by get3rdYear()
    //display L and thirdYear
    return 0;
}

void initList(List *P){
    int ndx;
    List temp;
    Record arr[] = {{12, {"Chris", "Vergara", 'S'}, "BSIT", 3}, {32, {"Dione", "Cabigas", 'A'}, "BSCS", 4}, {85, {"Jomer", "Barcenilla", 'G'}, "BSIS", 1}, {98, {"Danise", "Hinoguin", 'B'}, "BSIT", 1}, {456, {"Francis", "Aliser", 'C'}, "BSCS", 3},{888, {"Cody", "Ng", 'A'}, "BSIS", 3},{32,{"Jason", "Carreos", 'S'}, "BSIS", 3}};
    *P = NULL;
    for(ndx = 0; ndx!=7; ndx++){
        temp = (List)malloc(sizeof(struct node));
        if(temp != NULL){
            temp->student = arr[ndx];
            temp->link = *P;
            *P = temp;
        }
    }
}

List get3rdYear(List *P){
    List temp;
    temp = *P;
    while(temp != NULL){
        if(temp->student.yrlvl == 3){
            printf("%d\n",temp->student.id);
            printf("%s %s %c\n",temp->student.fullName.fName,temp->student.fullName.lName,temp->student.fullName.mI);
            printf("%s\n",temp->student.course);
            printf("%d\n",temp->student.yrlvl);
            temp = temp->link;
        }
    }
    return temp;
}

void displayBSIT(List P){
    List trav;
    trav = P;
    while(trav != NULL){
        if(trav->student.course == "BSIT"){
            printf("%d\n",trav->student.id);
            printf("%s %s %c\n",trav->student.fullName.fName,trav->student.fullName.lName,trav->student.fullName.mI);
            printf("%s\n",trav->student.course);
            printf("%d\n",trav->student.yrlvl);
            trav = trav->link;
        }
    }
}

void displayList(List P){
    List trav;
    trav = P;
    while(trav != NULL){
        printf("%d\n",trav->student.id);
        printf("%s %s %c\n",trav->student.fullName.fName,trav->student.fullName.lName,trav->student.fullName.mI);
        printf("%s\n",trav->student.course);
        printf("%d\n",trav->student.yrlvl);
        trav = trav->link;
    }
}```
#包括
#包括
#包括
#包括
类型定义结构{
char-fName[16];
字符名称[16];
查尔米;
}姓名;
类型定义结构{
int-id;
全名;
炭层[20];
int yrlvl;
}记录;
类型定义结构节点{
记录学生;
结构节点*链接;
}*名单;
无效初始列表(列表*P);
//创建以下函数:
第三年清单(清单*P);
无效显示BSIT(列表P);
无效显示列表(列表P);
/*
get3rdYear->从列表P中删除所有三年级学生。
所有三年制学生将被移至一个新的名单,并返回到
调用函数。
displayBSIT->如果课程是BSIT,则显示列表中的学生姓名
显示列表->显示列表中学生的全名
*/
内部主(空){
名单L,第三名;
初始列表(&L);
显示BSIT(L);
//第三年=第三年(&L);
显示列表(L);
//显示列表(第三方);
//通过调用initList()初始化L
//调用displayBSIT()
//调用get3rdYear(),thirdYear将接收get3rdYear()返回的列表
//显示L和thirdYear
返回0;
}
无效初始列表(列表*P){
int-ndx;
列表温度;
记录arr[]={12,{Chris”,“Vergara”,“S'},“BSIT”,3},{32,{Dione”,“Cabigas”,“A'},“BSC”,4},{85,{Jomer”,“Barcenilla”,“G'},“BSIS”,1},{98,{“Danise”,“Hinoguin”,“B'},“BSIT”,1},{456,{“Francis”,“Aliser”,“C'},“BSC'}”,3},{888,“Cody”,“Ng”,“Jason”,“BSIS”,“BSIS”,3},{;
*P=零;
对于(ndx=0;ndx!=7;ndx++){
temp=(列表)malloc(sizeof(结构节点));
如果(温度!=NULL){
临时->学生=arr[ndx];
温度->链接=*P;
*P=温度;
}
}
}
第三年列表(列表*P){
列表温度;
温度=*P;
while(temp!=NULL){
如果(temp->student.yrlvl==3){
printf(“%d\n”,temp->student.id);
printf(“%s%s%c\n”,temp->student.fullName.fName,temp->student.fullName.lName,temp->student.fullName.mI);
printf(“%s\n”,临时->学生课程);
printf(“%d\n”,temp->student.yrlvl);
温度=温度->链接;
}
}
返回温度;
}
无效显示BSIT(列表P){
列表trav;
trav=P;
while(trav!=NULL){
如果(trav->student.course==“BSIT”){
printf(“%d\n”,trav->student.id);
printf(“%s%s%c\n”,trav->student.fullName.fName,trav->student.fullName.lName,trav->student.fullName.mI);
printf(“%s\n”,trav->student.course);
printf(“%d\n”,trav->student.yrlvl);
trav=trav->link;
}
}
}
无效显示列表(列表P){
列表trav;
trav=P;
while(trav!=NULL){
printf(“%d\n”,trav->student.id);
printf(“%s%s%c\n”,trav->student.fullName.fName,trav->student.fullName.lName,trav->student.fullName.mI);
printf(“%s\n”,trav->student.course);
printf(“%d\n”,trav->student.yrlvl);
trav=trav->link;
}
}```

您的代码在此函数中有两个问题:

void displayBSIT(List P){
    List trav;
    trav = P;
    while(trav != NULL){
        if(trav->student.course == "BSIT"){
            printf("%d\n",trav->student.id);
            printf("%s %s %c\n",trav->student.fullName.fName,trav->student.fullName.lName,trav->student.fullName.mI);
            printf("%s\n",trav->student.course);
            printf("%d\n",trav->student.yrlvl);
            trav = trav->link;
        }
    }
}
首先,
==
不比较C中的字符串。因为字符串实际上是内存中第一个字符的地址,所以进行这种比较没有意义。既然我猜你们在做家庭作业,我将让你们学习如何比较C语言中的字符串

这里更重要的建议是:如果你的编译器没有告诉你这一点,你就做错了。当我运行它时(我必须将
conio
更改为
stdio
,因为
conio
是专有的),我得到以下警告:

> clang-7 -pthread -lm -o main main.c
main.c:84:33: warning: result of comparison against a string literal is unspecified (use strncmp instead) [-Wstring-compare]
        if(trav->student.course == "BSIT"){
                                ^  ~~~~~~
1 warning generated.
您可以看到它在下运行,这是一个受人尊敬的高质量编译器。您现在需要知道的最重要的事情是,编译器应该警告您也犯了错误

好的,第二个问题。让我澄清一下
displayBSIT
代码:

void displayBSIT(List P){
    List trav;
    trav = P;
    while(trav != NULL){
        if(trav->student.course == "BSIT"){
            printStudent(trav->student);
            trav = trav->link;
        }
    }
}
想一想。当当前节点有效时,如果当前节点的学生课程为
BSIT
,则打印并转到下一个节点。如果当前节点的学生课程不是BSIT,会发生什么?我们将进入下一个节点吗


这两个问题共同作用。您的比较不起作用,迭代也不起作用,因此您的程序没有提供任何有趣的输出。

您的代码在这两个函数中都有两个问题:

void displayBSIT(List P){
    List trav;
    trav = P;
    while(trav != NULL){
        if(trav->student.course == "BSIT"){
            printf("%d\n",trav->student.id);
            printf("%s %s %c\n",trav->student.fullName.fName,trav->student.fullName.lName,trav->student.fullName.mI);
            printf("%s\n",trav->student.course);
            printf("%d\n",trav->student.yrlvl);
            trav = trav->link;
        }
    }
}
首先,
==
不比较C中的字符串。因为字符串实际上是内存中第一个字符的地址,所以进行这种比较没有意义。既然我猜你们在做家庭作业,我将让你们学习如何比较C语言中的字符串

这里更重要的建议是:如果你的编译器没有告诉你这一点,你就做错了。当我运行它时(我必须将
conio
更改为
stdio
,因为
conio
是专有的),我得到以下警告:

> clang-7 -pthread -lm -o main main.c
main.c:84:33: warning: result of comparison against a string literal is unspecified (use strncmp instead) [-Wstring-compare]
        if(trav->student.course == "BSIT"){
                                ^  ~~~~~~
1 warning generated.
您可以看到它在下运行,这是一个受人尊敬的高质量编译器。您现在需要知道的最重要的事情是,编译器应该警告您也犯了错误

好的,第二个问题。让我澄清一下
displayBSIT
代码:

void displayBSIT(List P){
    List trav;
    trav = P;
    while(trav != NULL){
        if(trav->student.course == "BSIT"){
            printStudent(trav->student);
            trav = trav->link;
        }
    }
}
想一想。当当前节点有效时,如果当前节点的学生课程为
BSIT