多维数组和传输缓冲区 [英] multidimensional arrays and transferring buffers

查看:145
本文介绍了多维数组和传输缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存到缓冲区1800个字符数组段。当过我能够缓冲了转移,但是当我试图打印出每一个新的缓冲区。我得到空的输出。我究竟做错了什么?


编辑 - 我改变了循环到这对空端接添加到第二尺寸的末端。现在输出告诉我,这是空。但的printf(%C)表示,数据已经转移。

 而(buf_pos< msg_size + 1){
    如果(buf_pos%1800 == 0){
        msg_buff [KEY_NUM] [cbuf_pos] ='\\ 0';
        KEY_NUM ++;
        cbuf_pos = 0;
        msg_buff [KEY_NUM] [cbuf_pos] = BUF [buf_pos]
    }其他
        msg_buff [KEY_NUM] [cbuf_pos] = BUF [buf_pos]    的printf(%C,msg_buff [KEY_NUM] [cbuf_pos]);
    cbuf_pos ++;
    buf_pos ++;
}


解决方案

你在哪里递增 cbuf_pos ,分配给时msg_buff ?此外,在如果(buf_pos%1800 == 0)终止 msg_buff [KEY_NUM] [cbuf_pos] 与一个'\\ 0'(检查到有一个或多个字符左)。

I am trying to save a buffer into array segments of 1800 characters. When ever I am able to transfer the buffer over but when I try to print each new buffer out. I get null for the output. What exactly am I doing wrong?


EDIT - I changed the loop to this to add null terminations to the end of the 2nd dimension. now the output tell me it is null. But printf("%c") says the data has been transferred.

while(buf_pos < msg_size+1){
    if(buf_pos % 1800 == 0){
        msg_buff[key_num][cbuf_pos]='\0';
        key_num++;
        cbuf_pos=0;
        msg_buff[key_num][cbuf_pos]=buf[buf_pos];
    }else
        msg_buff[key_num][cbuf_pos]=buf[buf_pos];

    printf("%c",msg_buff[key_num][cbuf_pos]);
    cbuf_pos++;
    buf_pos++;
}

解决方案

Where are you incrementing the cbuf_pos, when assigning to the msg_buff? Also, in the if(buf_pos % 1800 ==0), terminate the msg_buff[key_num][cbuf_pos] with a '\0' (checking that there is one more character left).

这篇关于多维数组和传输缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆