结构体指针与结构体变量指针的区别, 在进行实现的工程项目中会有许多地方用到结构体指针的情况,
这只是结构体指针最简单一点操作,经常可以在对链表的操作中见到,以及一些结构算法中运用,必须要熟悉的掌握。。。
在使用这前都需要先malloc一块空间之后才能有空间进入存储数据,实例代码如下:
#include<stdio.h>
#include<string.h>
typedef struct student
{
int No;
char *name;
char score[4];
struct student *nextStu;
} STUDENT_T,*PSTUDENT_T;
void printList(PSTUDENT_T stu)
{
while(stu != NULL)
{
printf("No:%d\tName:%s\tScore:%s\n", stu->No, stu->name, stu->score);
stu = stu->nextStu;
}
}
int main(int argc, char *argv[])
{
STUDENT_T student1;
PSTUDENT_T student2=NULL;
PSTUDENT_T head=NULL;
student2 = (PSTUDENT_T)malloc(sizeof(STUDENT_T));
student2->name = (char *)malloc(sizeof(char));
student2->No = 1002;
strcpy(student2->name, "weizhong");
strcpy(student2->score, "98");
student1.No = 1001;
student1.name = (char *)malloc(sizeof(char));
strcpy(student1.name, "baiyang");
strcpy(student1.score, "99");
student2->nextStu = NULL;
head = &student1;
student1.nextStu = student2;
printList(head);
free(head);
return 0;
}
这只是结构体指针最简单一点操作,经常可以在对链表的操作中见到,以及一些结构算法中运用,必须要熟悉的掌握。。。