使用指针从链表中删除数据

时间:2016-02-15 06:21:00

标签: pointers linked-list dereference

我试图提出一个程序,该程序将使用链接列表从文件中读取数据并删除低于50%的成绩。我想出了这个代码,但它给了我错误“type float' argument given to 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
    {

这就是我的问题所在。我不知道如何在这里解决这个问题。

        if( np->grade <50 )
        np->grade = delete(np->grade);**
    else 

      if(np->grade > 60)
        np->grade = np->grade;

   }

  }

0 个答案:

没有答案