|
发表于 2011-8-6 14:45:17
|
显示全部楼层
我把你那个代码前边稍微改了一下!你后边那个scanf也有错误!你自己调试吧!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- typedef struct students{
- int num;
- float score;
- struct students *next;
- } st;
- int n = 0;
- st *p1,*p2,*head;
- int main(void)
- {
- void print(st *);
- void dele(st *);
-
- p1= (st *)malloc(sizeof(st));
- head = p1;
- printf("请输入学生的数据:\n");
- scanf("%d",&p1->num);
- printf("score\n");
- scanf("%f",&p1->score); /* <<<<<<<<<<---------------*/
- /*p1->next = NULL;
-
- while (p1->num)
- {
- n++;
- p2 = p1;
- p1 = (st *)malloc(sizeof(st));
- p2->next = p1;
- printf("请输入学生的数据:\n");
- scanf("%d",&p1->num);
- printf("score\n");
- scanf("%f",&p1->score);
- }
- p2->next = NULL;
- print(head);
- dele(head);*/
- return 0;
- }
- /*
- void print(st *head)
- {
- int i ;
- for (i = 1; i<=n;i++) {
-
- printf("num: %d \t",head->num);
- printf("score:%f \t",head->score);
- head = head->next;
- if (i%2==0)
- printf("\n");
- }
- }
- void dele(st *p)
- {
- int find,boo=0,i;
- printf("please inpput the num\n");
- scanf("%d",&find);
- p1=p;
- for (i=1;i<=n;i++) {
-
- if(strcmp(find,p1->num)==0 && i==1) {
-
- head=p1->next;
- p1->next=NULL;
- boo=1;
- }
- if(strcmp(find,p1->num)==0 && i>1) {
-
- p2->next=p1->next;
- p1->next=NULL;
- boo=1;
- }
- else {
- p2=p1;
- p1=p1->next;
- }
- }
- if(boo==0)
- printf("sorry,there is no data of your num\n");
- }
- */
复制代码
|
|