将数组传递到函数,然后测试显示其中的数值;结果编译提示错误:
d:\test_list\test.c(38) : warning C4047: 'function' : 'struct students *' differs in levels of indirection from 'struct students *[64]'
d:\test_list\test.c(38) : warning C4024: 'showInfo' : different types for formal and actual parameter 1#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
  typedef struct
{  
     char xh[3];     //序号 
   char name[16];  //姓名
 
}students,    *studentPtr;
void showInfo(studentPtr stu,int count)
{
int i;
for(i=0;i<count;i++)
{
    printf("%s",stu[i].xh);
printf("%s\n",stu[i].name);
}
}
int main(int argc, char *argv[])
{
int totalCount=0;
    studentPtr    studentA[MAXIMUM_WAIT_OBJECTS]; 
    studentA[totalCount] = (studentPtr)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(studentPtr));    strcpy(studentA[totalCount]->xh,"01");
    strcpy(studentA[totalCount]->name,"nike");
    ++totalCount;    strcpy(studentA[totalCount]->xh,"02");
    strcpy(studentA[totalCount]->name,"liping");
    ++totalCount;

  
    showInfo(studentA,totalCount);
}我将 showInfo(studentA,totalCount);修改为:
 showInfo(studentA[MAXIMUM_WAIT_OBJECTS],totalCount);编译通过,但是运行错误:内存不能为written;

解决方案 »

  1.   

    如果你改了的话,应该这么调用showInfo(&studentA,totalCount);
      

  2.   

    void showInfo(studentPtr& stu,int count)
    传引用
      

  3.   

    void showInfo(studentPtr *stu,int count)
      

  4.   

    修改后;编译通过;但是运行错误:该内存不能written#include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>  typedef struct
    {  
         char xh[3];     //序号 
          char name[16];  //姓名
     
    }students,    *studentPtr;
    void showInfo(studentPtr *stu,int count)
    {
    int i;
    for(i=0;i<count;i++)
    {
        printf("%s",stu[i]->xh);
    printf("%s\n",stu[i]->name);
    }
    }
    int main(int argc, char *argv[])
    {
    int totalCount=0;
        studentPtr    studentA[MAXIMUM_WAIT_OBJECTS]; 
        studentA[totalCount] = (studentPtr)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(studentPtr));    strcpy(studentA[totalCount]->xh,"01");
        strcpy(studentA[totalCount]->name,"nike");
        ++totalCount;    strcpy(studentA[totalCount]->xh,"02");
        strcpy(studentA[totalCount]->name,"liping");
        ++totalCount;    showInfo(studentA,totalCount);
    }
      

  5.   

    studentA[totalCount] = (studentPtr)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(studentPtr));
    只分配了一个内存吧,后面的没有分配
      

  6.   

    正确:#include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
      typedef struct
    {  
         char xh[3];     //序号 
          char name[16];  //姓名
     
    }students,    *studentPtr;
    void showInfo(studentPtr *stu,int count)
    {
    int i;
    for(i=0;i<count;i++)
    {
        printf("%s",stu[i]->xh);
    printf("%s\n",stu[i]->name);
    }
    }
    int main(int argc, char *argv[])
    {
    int totalCount=0;
        studentPtr    studentA[MAXIMUM_WAIT_OBJECTS]; 
        studentA[totalCount] = (studentPtr)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(studentPtr));    strcpy(studentA[totalCount]->xh,"01");
        strcpy(studentA[totalCount]->name,"nike");
        ++totalCount;  studentA[totalCount] = (studentPtr)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(studentPtr));
        strcpy(studentA[totalCount]->xh,"02");
        strcpy(studentA[totalCount]->name,"liping");
        ++totalCount;

      
        showInfo(studentA,totalCount);

      

  7.   

    弱弱的问问 sizeof(studentPtr) 等于多少