的memcpy() [英] memcpy()
问题描述
你好!
我有两种结构:
- 在这里切割 -
const unsigned int max_pkg_data = 5000;
typedef struct pkg_ {
short int info;
short int size;
char数据[max_pkg_data];
} pkg;
typedef struct binary_ {
char * buffer ;
int size;
}二进制;
- 在这里切割 -
和我不明白,为什么这个功能不起作用:
- 在这里切 -
void SendBinary(二进制和发送)
{
unsigned int n = 0;
for(n = 0; n< sent.size / max_pkg_data; ++ n)
{
pkg nPkg;
memcpy((void *)nPkg.data,(void *)sent.buffer [n * max_pkg_data],max_pkg_data);
nPkg.info = 0;
nPkg.size = max_pkg_data;
// tu wpisujesz swoj kod do obs3ugi binary
Form1 - > CC1-> Socket-> SendBuf((void *)& nPkg,sizeof(pkg));
}
pk g nPkg;
memcpy((void *)nPkg.data,(void *)sent.buffer [n * max_pkg_data],max_pkg_data);
nPkg.info = 0 ;
nPkg.size = sent.size - ((n)* max_pkg_data);
Form1-> CC1-> Socket-> SendBuf((void *) )& nPkg,sizeof(pkg));
返回;
}
- 在这里切 -
Especcialy:
memcpy((void *)nPkg.data,(void *)sent.buffer [n * max_pkg_data],max_pkg_data);
给我一个Acces违规消息?为什么会这样?有人可以帮帮我吗?
-
ishmael4
hello!
i''ve go two structures:
--cut here--
const unsigned int max_pkg_data=5000;
typedef struct pkg_ {
short int info;
short int size;
char data[max_pkg_data];
} pkg;
typedef struct binary_ {
char* buffer;
int size;
} binary;
--cut here--
and i cant understand, why isnt this function working:
--cut here--
void SendBinary(binary& sent)
{
unsigned int n=0;
for (n=0;n<sent.size/max_pkg_data;++n)
{
pkg nPkg;
memcpy((void*)nPkg.data,(void*)sent.buffer[n*max_pkg_data],max_pkg_data);
nPkg.info=0;
nPkg.size=max_pkg_data;
// tu wpisujesz swoj kod do obs3ugi binary
Form1->CC1->Socket->SendBuf((void*)&nPkg,sizeof(pkg));
}
pkg nPkg;
memcpy((void*)nPkg.data,(void*)sent.buffer[n*max_pkg_data],max_pkg_data);
nPkg.info=0;
nPkg.size=sent.size-((n)*max_pkg_data);
Form1->CC1->Socket->SendBuf((void*)&nPkg,sizeof(pkg));
return;
}
--cut here--
Especcialy:
memcpy((void*)nPkg.data,(void*)sent.buffer[n*max_pkg_data],max_pkg_data);
Gives me an Acces Violation Message? Why is it so? Anyone could help me?
--
ishmael4
推荐答案
ishmael4写道:
ishmael4 wrote:
你好!
我有两种结构:
- 在这里 -
const unsigned int max_pkg_data = 5000;
typedef struct pkg_ {
short int info;
short int size;
char data [max_pkg_data];
} pkg;
typedef struct binary_ {
char * buffer;
int size;
} binary;
--cut here--
而且我无法理解,为什么这个功能不起作用:
- 这里 -
void SendBinary(二进制和发送)
{uns / unsigned int n = 0 ;
for(n = 0; n< sent.size / max_pkg_data; ++ n)
{
pkg nPkg;
memcpy((void *)nPkg.data,( void *)sent.buffer [n * max_pkg_data],max_pkg_data);
nPkg.info = 0;
nPkg.size = max_pkg_data;
// tu wpisujesz swoj kod do obs3ugi binary
Form1-> CC1-> Socket-> SendBuf((void *)& nPk g,sizeof(pkg));
}
pkg nPkg;
memcpy((void *)nPkg.data,(void *)sent.buffer [n * max_pkg_data],max_pkg_data);
nPkg.info = 0;
nPkg.size = sent.size - ((n)* max_pkg_data);
Form1-> CC1-> Socket-> SendBuf((无效) *)& nPkg,sizeof(pkg));
返回;
}
- 在这里切割 -
Especcialy:
memcpy((void *)nPkg.data,(void *)sent.buffer [n * max_pkg_data],max_pkg_data);
给我一个Acces违规消息?为什么会这样?有人可以帮帮我吗?
-
ishmael4
hello!
i''ve go two structures:
--cut here--
const unsigned int max_pkg_data=5000;
typedef struct pkg_ {
short int info;
short int size;
char data[max_pkg_data];
} pkg;
typedef struct binary_ {
char* buffer;
int size;
} binary;
--cut here--
and i cant understand, why isnt this function working:
--cut here--
void SendBinary(binary& sent)
{
unsigned int n=0;
for (n=0;n<sent.size/max_pkg_data;++n)
{
pkg nPkg;
memcpy((void*)nPkg.data,(void*)sent.buffer[n*max_pkg_data],max_pkg_data);
nPkg.info=0;
nPkg.size=max_pkg_data;
// tu wpisujesz swoj kod do obs3ugi binary
Form1->CC1->Socket->SendBuf((void*)&nPkg,sizeof(pkg));
}
pkg nPkg;
memcpy((void*)nPkg.data,(void*)sent.buffer[n*max_pkg_data],max_pkg_data);
nPkg.info=0;
nPkg.size=sent.size-((n)*max_pkg_data);
Form1->CC1->Socket->SendBuf((void*)&nPkg,sizeof(pkg));
return;
}
--cut here--
Especcialy:
memcpy((void*)nPkg.data,(void*)sent.buffer[n*max_pkg_data],max_pkg_data);
Gives me an Acces Violation Message? Why is it so? Anyone could help me?
--
ishmael4
是什么让你认为你的缓冲区是
$ b的精确倍数$ b max_pkg_data的大小?例如,假设缓冲区是4个字节。
您将复制这4个字节,但也会复制下一个4996个字节,您需要b $ b不应该读取。
-David
What makes you think that your buffer is an exactl multiple of
max_pkg_data in size? For example, suppose that buffer is 4 bytes.
You will copy those 4 bytes, but also the next 4996 bytes, which you
ought not be reading.
-David
ishmael4写于09/22/05 12:47,:
ishmael4 wrote On 09/22/05 12:47,:
你好!
我有两个结构:
- 在这里 -
const unsigned int max_pkg_data = 5000;
typedef struct pkg_ {
short int info;
short int size;
char data [max_pkg_data];
[。 ..]
hello!
i''ve go two structures:
--cut here--
const unsigned int max_pkg_data=5000;
typedef struct pkg_ {
short int info;
short int size;
char data[max_pkg_data];
[...]
comp.lang.c ++在你左边的大厅里,只需
经过自动售货机。
-
Er ********* @ sun。 com
comp.lang.c++ is down the hall to your left, just
past the vending machines.
--
Er*********@sun.com
Uzytkownik" Eric Sosman" < ER ********* @ sun.com> napisal w wiadomosci
新闻:dg ********** @ news1brm.Central.Sun.COM ...
Uzytkownik "Eric Sosman" <er*********@sun.com> napisal w wiadomosci
news:dg**********@news1brm.Central.Sun.COM...
> ishmael4写于09/22/05 12:47,:
ishmael4 wrote On 09/22/05 12:47,:
你好!
我有两种结构:
- 切到这里 -
const unsigned int max_pkg_data = 5000;
typedef struct pkg_ {
short int info;
short int size;
char数据[ max_pkg_data];
[...]
hello!
i''ve go two structures:
--cut here--
const unsigned int max_pkg_data=5000;
typedef struct pkg_ {
short int info;
short int size;
char data[max_pkg_data];
[...]
comp.lang.c ++位于您左边的大厅,只是通过自动售货机。
>
-
Er ********* @ sun.com
为什么你认为它的c ++?
ishmael4
why do you think its c++?
ishmael4
这篇关于的memcpy()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!