将数组传递到函数,然后测试显示其中的数值;结果编译提示错误:
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;
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;
解决方案 »
- 关于函数返回字符串问题...有种写了个字但是越看越不对的感觉
- 进程退出的清理问题
- CListCtrl要其中一列显示图标如何弄?第一列是可以了谢谢!
- 出学者问,高分求解,有关CDHtmlDialog的问题
- 回调的问题
- 求(重庆)电信面试题目以及其他技巧.----求斑竹不要del掉,周二就移走.
- 用webBrowser的时候,请问怎么实现类似IE的“查看源文件”的功能?我想既然网页都显示出来了,这些源码应该在硬盘上了,怎么找到他们呢?
- 谁能帮帮我,解决VC++ 6.0安装问题?
- 拜托~~急~~多谢~~~
- 500分求助,一个关于动态链接库的问题
- 修改工程输出目录引起的tlb文件找不到的问题
- “仅通过崩溃地址找出源代码的出错行”
传引用
#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);
}
只分配了一个内存吧,后面的没有分配
#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);
}