注册 登录
编程论坛 数据结构与算法

结构指标数组参数传递的问题....求高手!!!!

恰擊 发布于 2011-11-23 11:50, 581 次点击
在MAIN函式里,当我将结构数组emp[5]定义为指标时,VOID函式可以运行,
但我把emp[5]定义为一个时,函式就不能运行,其错误报告为:   
  cannot convert `Employee (*)[5]' to `Employee**' for argument `1' to `void stat(Employee**)'
 
下面是我的编码:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define max 100
struct Date{
  int year;
  int month;
  int day;      
};
 
struct Employee{
  int EmpID;    // starting from 111111
  Date dob;    //  day of birth
  int Salary;   //  between 20000~70000
  char Sex;     // M for Male, F for Female
};
 
void stat(struct Employee *hi[]){
    int i,s;
    for(i=0;i<5;i++){
        hi[i]=(struct Employee *)malloc(sizeof(struct Employee));
        }
    srand(time(NULL));
    for(i=0;i<5;i++){
        s=rand()%1;
        if(s==0){
            hi[i]->Sex='M';
            }
        else
            hi[i]->Sex='F';
        }
    for(i=0;i<5;i++){
        s=20000+rand()%50000;
        hi[i]->Salary=s;
        }

    }
int main(){
    int i;
    struct Employee emp[5];
    stat(&emp);
    printf(" EmpID   Sex   Birthday   Salary ");
    printf("---------------------------------");
    printf("\n");
    for(i=0;i<5;i++){
        printf("11111%d    ",i+1);
        printf("%c   ",emp[i].Sex);
        printf("%2d/%2d/%d",emp[i].dob);
        printf("\n");
        }
    system("pause");
    }
0 回复
1