c语言 编程 数据结构
我想问问字节还有地址?不是数值有地址么?如果有和数值的地址区别是啥
我想问问字节还有地址?不是数值有地址么?如果有和数值的地址区别是啥
答案:字节只是表示数据的大小,它是一个量纲,就像我们说,“一个桌子1m长”,不能说我们还得给这样一个称呼定义一个内存(因为它是虚有的),而1m是一个数值! http://baike.zhaoxi.net/view/60408.htm 百科参考
其他:#include "stdio.h" #include <malloc.h> #include <stdlib.h> #include <string> struct Student { int num; char name[20]; int 易做图;//0女,1男 int score; }stu; struct list { struct Student student; struct list *next; }; struct list *CreatFemale(struct list *head,struct Student stu)//女生信息 { struct list *p; struct list *p1,*p2; p = head; p1 = (struct list *)malloc(sizeof(struct list)); p1->student = stu; if (head == NULL) { head = p1; p1->next = NULL; } else { while (p->next != NULL && stu.score >= p->student.score) { p2 = p; p = p->next; } if (stu.score < p->student.score) { if (p == head) { head = p1; p1->next = p; } else { p2->next = p1; p1->next = p; } } else { p->next = p1; p1->next = NULL; } } return head; } struct list *CreatMale(struct list *head,struct Student stu)//男生信息 { struct list *p; struct list *ptr; struct list *q; struct list *p1,*p2; q = head; ptr = head; p1 = (struct list *)malloc(sizeof(struct list)); p1->student = stu; while (q->next != NULL && q->student.易做图 == 0) { ptr = q; q = q->next; } p = q; if (head == NULL) { head = p1; p1->next = NULL; } else { while (p->next != NULL && stu.score >= p->student.score) { p2 = p; p = p->next; } if (stu.score < p->student.score && p->student.易做图 == 1) { if (p == q ) { p = p1; ptr->next = p1; p1->next = q; } else { p2->next = p1; p1->next = p; } } else { p->next = p1; p1->next = NULL; } } return head; } void Print(struct list *head)//输出到文件 { FILE *fp; char Sex[10]; fp = fopen("data1.txt","w"); if (fp == NULL) { printf("can't open the file!\n"); exit(0); } struct list *p; struct list *q; p = head; while (p != NULL) { if (p->student.易做图 == 0) { strcpy(Sex,"女"); } else { strcpy(Sex,"男"); } fprintf(fp,"%d %s %s %d\n",p->student.num,p->student.name,Sex,p->student.score); q = p->next; free(p); p = q; } fclose(fp); } main() { struct list *head; FILE *fp; head = NULL; fp = fopen("data.txt","r"); if (fp == NULL) { printf("can't open the file!\n"); exit(0); } while (!feof(fp)) { fscanf(fp,"%d%s%*c%d%d",&stu.num,stu.name,&stu.易做图,&stu.score); if (stu.易做图 == 0) { head = CreatFemale(head,stu);//女 } } fseek(fp,0L,0); while (!feof(fp)) { fscanf(fp,"%d%s%*c%d%d",&stu.num,stu.name,&stu.易做图,&stu.score); if (stu.易做图 == 1) { head = CreatMale(head,stu);//男的 } } fclose(fp); Print(head); }爱洗澡小鳄鱼W8! 无地址
上一个:孙鑫mfc视频教程第几个讲到串口通信的?
下一个:C语言中,while语句中如果有是 int y=10; while(--y);那么while中的判断条件是什么?