内容来源 : 郝斌
#include <stdio.h>
#include <string.h>
void f( struct Student * pst ) ; //注意不可写成 f();
void g( struct Student * pst ) ;
struct Student
{
int sid ;
char name[200] ; //定义一个数据类型 struct Student(结构体)
int age ;
};//分号不能省
int main ()
{
struct Student st ;
f( &st ) ;
g( &st ) ;
return 0 ;
}
//赋值函数
void f(struct Student * pst )
{
int a;
int b;
printf ("请输入sid值:");
scanf ( "%d", &a) ;
printf ("请输入age值:");
scanf ( "%d", &b) ;
pst ->sid = a ;
// st.name = "zhangsan" ; 这样是错误的
strcpy ( pst -> name , "zhangsan") ; //strcpy在<string.h>中
pst ->age = b ;
}
/*输出函数1(这种方式浪费内存和时间一般不用)
void g (struct student st)
{
printf ( "%d %s %d\n" , st->sid , st->name , st->age ) ;
} */
//输出函数2
void g (struct Student * pst)
{
printf ( "%d %s %d\n" , pst->sid , pst->name , pst->age ) ;
}