我在 C 应用程序中有一个字符数组,我必须将其拆分为 250 个的部分,以便我可以将它发送到另一个一次不接受更多的应用程序。

我该怎么做?平台:win32。

最佳答案

从 MSDN 文档:



请注意,strncpy 不检查有效的目标空间;这是留给程序员的。原型(prototype):
char *strncpy( char *strDest, const char *strSource, size_t count);
扩展示例:

void send250(char *inMsg, int msgLen)
{
    char block[250];
    while (msgLen > 0)
    {
         int len = (msgLen>250) ? 250 : msgLen;
         strncpy(block, inMsg, 250);

         // send block to other entity

         msgLen -= len;
         inMsg  += len;
    }
}

关于c - 如何从char数组中检索n个字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/162804/

10-11 23:55
查看更多