vc 编译出错的小问题

byybyybyy 2003-08-27 10:59:58
win2000,vc6.0控制台做了小程序。共三个文件,libcpp.h(定义了一个struct结构)
libcpp.cpp(是struct结构的内部函数实现)
testlibcpp.cpp(是一个主函数)遇到一点小困难,请求帮助。
源代码和出错信息如下
我是新手,高手一看会马上知道答案的

源码:

//libcpp.h

struct stash
{
//properties
int size;
int quantity;
int next;
unsigned char* storage;
//functions
void initialize(int Size);
void cleanup();
int add(void* element);
void * fetch(int index);
int count();
void inflate(int increase);
};



//libcpp.cpp
#include "libcpp.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

void stash::initialize(int Size)
{
size = Size;
quantity = 0;
next = 0;
storage = 0;
}

void stash::cleanup()
{
if (storage)
{
puts("freeing storage");
free(storage);
}
}

int stash::add(void * element)
{
if (next >= quantity)
inflate(100);
memcpy(&(storage[next * size]), element, size);
next++;
return(next - 1);
}

void * stash::fetch(int index)
{
if (index >= next || index < 0)
return 0;
return &(storage[size * index]);
}

int stash::count()
{
return next;
}

void stash::inflate(int increase)
{
void * v = realloc(storage, (quantity + increase) * size);
assert(v);
storage = (unsigned char *)v;
quantity += increase;
}



//testlibcpp.cpp

#include "libcpp.h"
#include <assert.h>
#include <stdio.h>
#define BUFSIZE 80

int main()
{
stash intStash, stringStash;
int i;
FILE * file;
char buf[BUFSIZE];
char * cp;
intStash.initialize(sizeof(int));
for (i=0; i<100; i++)
intStash.add(&i);
stringStash.initialize(sizeof(char) * BUFSIZE);
file = fopen("testlibcpp.cpp", "r");
assert(file);
while(fgets(buf, BUFSIZE, file))
stringStash.add(buf);
fclose(file);
for (i = 0; i < intStash.count(); i++)
printf("intStash.fetch(%d) = %d\n", i, *(int *)intStash.fetch(i));
i = 0;
while((cp = (char *)stringStash.fetch(i++)) != 0)
printf("stringStash.fetch(%d) = %s", i - 1, cp);
putchar('\n');
intStash.cleanup();
stringStash.cleanup();
return 0;
}

...全文
86 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
whoo 2003-08-27
  • 打赏
  • 举报
回复
晕,出错信息在哪儿?
farfh 2003-08-27
  • 打赏
  • 举报
回复
up
zhouyong0371 2003-08-27
  • 打赏
  • 举报
回复
或者直接
Project->Settings
C/C++页Project Options里有一个_WINDOWS改为_CONSOLE
Link页Project Options里有一个windows,改为console就可以了。
zhouyong0371 2003-08-27
  • 打赏
  • 举报
回复
你建成Win32 Application了,你应该建一个Win32 console Application,然后添加你的文件就可以了。
byybyybyy 2003-08-27
  • 打赏
  • 举报
回复
不好意思,错误如下:


--------------------Configuration: structhigh - Win32 Debug--------------------
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/structhigh.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Creating browse info file...

structhigh.exe - 2 error(s), 0 warning(s)

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧