一段报错的c程序,帮帮忙

[复制链接]
查看11 | 回复2 | 2008-11-11 13:09:02 | 显示全部楼层 |阅读模式
#include
#include
#include
char mybuf[] = "ww0830";
int main (int argc, char *argv[])
{
HANDLE hHeap;
char *buf1, *buf2;
//我们自己建立一个HEAP
hHeap = HeapCreate(HEAP_GENERATE_EXCEPTIONS, 0x10000, 0xfffff);
printf("mybuf addr = %p\n",mybuf);
//动态分配buf1
buf1 = HeapAlloc(hHeap, 0, 200);
strcpy(buf1,mybuf);
printf("buf1 = %s\n",buf1);
//动态分配buf2
buf2 = HeapAlloc(hHeap, 0, 16);
HeapFree(hHeap, 0, buf1);
HeapFree(hHeap, 0, buf2);
return 0;
}
编译运行提示如下
--------------------Configuration: test - Win32 Release--------------------
Compiling...
test.cpp
D:\vc-project\test\test.cpp(13) : error C2440: '=' : cannot convert from 'void *' to 'char *'

Conversion from 'void*' to pointer to non-'void' requires an explicit cast
D:\vc-project\test\test.cpp(18) : error C2440: '=' : cannot convert from 'void *' to 'char *'

Conversion from 'void*' to pointer to non-'void' requires an explicit cast
执行 cl.exe 时出错.
test.exe - 1 error(s), 0 warning(s)
大家看看,改怎么改

回复

使用道具 举报

千问 | 2008-11-11 13:09:02 | 显示全部楼层
#include#include#includechar mybuf[] = "ww0830"; int main (int argc, char *argv[]) { HANDLE hHeap; char *buf1, *buf2; //我?自己建立一个HEAP hHeap = HeapCreate(HEAP_GENERATE_EXCEPTIONS, 0x10000, 0xfffff); printf("mybuf addr = %p\n",mybuf); //??分配buf1 buf1 = (char*)HeapAlloc(hHe...
回复

使用道具 举报

千问 | 2008-11-11 13:09:02 | 显示全部楼层
你的程序我运行怎么是正确的,呵呵,我运行了俩次。...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行