/* * File: main.c * Author:CuHwz * * Created on 2010年8月22日, 下午11:32 */ #include <stdio.h> #include <stdlib.h> /* * */ int (* funcp)(int); int getInt(int); int call_user_func(int, int (* funcp)(int b)); struct worker { char name[20]; int age; float salary; struct worker *next; }; union uid{ int id; }; struct worker *create(); void readWorker(struct worker *header); int main() { int c = call_user_func(1, getInt); printf("%d", c); struct worker *workers=create(); readWorker(workers); return 1; } int call_user_func(int a, int (* funcp)(int b)) { int c = (* funcp)(a); return c; } int getInt(int b) { return b; } struct worker *create() { struct worker *header,*p1,*p2; header=NULL; int n; n=0; p1=(struct worker *)malloc(sizeof(struct worker)); printf("please input the worker's name:"); scanf("%s",&p1->name); printf("please input the worker's age:"); scanf("%d",&p1->age); printf("please input the worker's salary:"); scanf("%f",&p1->salary); for(n;n<5;n++) { if(n==0) { header=p1; p2=p1; p2->next=NULL; } p2->next=p1; p2=p1; p1=(struct worker *)malloc(sizeof(struct worker)); printf("please input the worker's name:"); scanf("%s",&p1->name); printf("please input the worker's age:"); scanf("%d",&p1->age); printf("please input the worker's salary:"); scanf("%f",&p1->salary); } free(p1); p2->next=NULL; return header; } void readWorker(struct worker *header) { struct worker *current; current=header; do{ printf("this worker's name is:%s",current->name); printf("this worker's age is:%d",current->age); printf("this worker's salary is:%f",current->salary); current=current->next; }while(current); }