本文介绍了的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 binaryForm1->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 ofmax_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 youought not be reading. -David comp.lang.c ++在你左边的大厅里,只需 经过自动售货机。 - Er ********* @ sun。 com comp.lang.c++ is down the hall to your left, justpast the vending machines. -- Er*********@sun.com comp.lang.c ++位于您左边的大厅,只是通过自动售货机。 > - Er ********* @ sun.com 为什么你认为它的c ++? ishmael4 why do you think its c++? ishmael4 这篇关于的memcpy()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-20 15:21