Pointers 使用指针从链表中删除数据
我试图想出一个程序,使用链表从文件中读取数据并删除低于50%的分数。我想出了这段代码,但它给了我一个错误“typePointers 使用指针从链表中删除数据,pointers,linked-list,dereference,Pointers,Linked List,Dereference,我试图想出一个程序,使用链表从文件中读取数据并删除低于50%的分数。我想出了这段代码,但它给了我一个错误“typefloat”参数给了delete',预期的指针”。如果可以的话,请帮忙 #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<string.h> struct node { int id; char name[10]; float
float”参数给了
delete',预期的指针”。如果可以的话,请帮忙
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
struct node
{
int id;
char name[10];
float grade;
struct node * next;
};
void build_link(struct node * ap);
void happy (struct node * bp);
void delete_fail (struct node *np);
int main(int argc, char *argv[])
{
struct node head;
head.next = NULL;
build_link( &head);
happy(head.next);
delete_fail (head.next);
system("PAUSE");
return 0;
}
void build_link(struct node * tmp)
{
int nu_id;
char nu_nam[10];
float nu_grade;
struct node * np;
FILE *fp;
fp = fopen("Student.txt","r");
while (fscanf( fp,"%d %s %f", &nu_id, nu_nam, &nu_grade ) != EOF)
{
np = (struct node *) malloc ( sizeof (struct node) );
strcpy (np->name,nu_nam);
np->id = nu_id;
np->grade = nu_grade;
np->next = NULL;
tmp->next = np;
tmp = tmp->next;
}
}
void happy(struct node *np)
{
while (np != NULL)
{
printf(" %d %s %f \n", np->id, np->name, np->grade);
np = np->next;
}
}
void delete_fail(struct node* grade)
{
node *np;
if(np == NULL)
printf("\nElement not found");
else
{
#包括
#包括
#包括
#包括
结构节点
{
int-id;
字符名[10];
浮子等级;
结构节点*下一步;
};
无效构建链接(结构节点*ap);
void happy(结构节点*bp);
void delete_失败(结构节点*np);
int main(int argc,char*argv[])
{
结构节点头;
head.next=NULL;
建立链接(&head);
快乐(头,下一个);
删除_fail(head.next);
系统(“暂停”);
返回0;
}
无效构建链接(结构节点*tmp)
{
int nu_id;
查努南[10];
浮点数;
结构节点*np;
文件*fp;
fp=fopen(“Student.txt”,“r”);
而(fscanf(fp、%d%s%f、&nu\u id、nu\u nam和nu\u grade)!=EOF)
{
np=(结构节点*)malloc(sizeof(结构节点));
strcpy(np->name,nu_nam);
np->id=nu\u id;
np->grade=nu\U grade;
np->next=NULL;
tmp->next=np;
tmp=tmp->next;
}
}
void happy(结构节点*np)
{
while(np!=NULL)
{
printf(“%d%s%f\n”,np->id,np->name,np->grade);
np=np->next;
}
}
无效删除失败(结构节点*等级)
{
node*np;
if(np==NULL)
printf(“\n未找到元素”);
其他的
{
这就是我的问题所在。我不知道如何修复这部分
if( np->grade <50 )
np->grade = delete(np->grade);**
else
if(np->grade > 60)
np->grade = np->grade;
}
}
if(np->grade-grade=delete(np->grade)**
其他的
如果(np->等级>60)
np->grade=np->grade;
}
}
delete\u fail(结构节点*grade)的真正功能是什么?指针grade
作为参数发送,但从未在内部使用。本地node*np;
从未初始化,而是与NULL
进行比较,然后比较其属性grade
。在truct node*grade
和node*np;
之间有一个很大的混合体delete\u失败的真实性(结构节点*等级)
?指针grade
作为参数发送,但从未在内部使用。本地节点*np;
从未初始化,而是与NULL
进行比较,然后比较其属性grade
。在truct节点*grade
和节点*np;
之间存在很大的混合!!!!