如何在表[0]和表[1]之间插入值? [英] How do I insert value between table[0] and table [1]?

查看:68
本文介绍了如何在表[0]和表[1]之间插入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友

我想用c语言编辑我的程序,在表格的第一个插入一个新值,这是我原来的程序和评论我试过的!

我的程序将是这样的:

Moins val = 0

加val = 1

-------- ---

Moins 0 = val

加0 = 2

----------

Moins 1 = 2

加1 = 3







Moins 255 = 256

加255 = 257

这意味着在0和1之间的新插入字符

字符零范围1和2之间

范围2和3之间的字符1

范围3和4之间的字符2



我的尝试:



Hi friends
I want do edit my program in c language for insert a new value in the first of table , this is my original program and a comment what I tried !
My program will be like that :
Moins val = 0
Plus val = 1
-----------
Moins 0 = val
Plus 0 = 2
----------
Moins 1 = 2
Plus 1 = 3
.
.
.
Moins 255 = 256
Plus 255 = 257
It means new insert char val between interval 0 and 1
Char of zero between range 1 and 2
Char of 1 between range 2 and 3
Char of 2 between range 3 and 4

What I have tried:

#define plus(c)       (c+1)
#define moins(c)      (c)

Int main ()
{
    Int arrayCount[256];//number of ascii code
    Int range[plus(256)];//table of all ascii counted
    Int c;
    For (c=0;c<256;c++)
    {
        ArrayCount[c]=0;
    }
    While (c=fgetc(file))//file is opened with image grey scale
    {
        ArrayCount[c]++;
    }

    Moy[0]=0;
//  Moy[1]=tab[257];
    For(c=0;c<=257;c++)
    {
        Range[plus(c)]=tab[c];
    }
    For(c=1;c<=257;c++)
    {
        Range[c]=range[c]+range[c-1];

推荐答案

在C中,您必须分配一个足够大的新数组并复制所有需要的值。一个很好的 Youtube教程



在C ++中你可以使用向量或其他支持可更改数组的类。
In C you must allocate a new and big enough array and copy all needed values. A nice Youtube tutorial.

In C++ you could use a vector or some other classes which support changeable arrays.


这是一种向下移动数组并插入新值的方法:



Here is one way to move an array down and insert a new value :

#define ArraySize 256
int range[ArraySize];
memmove( &range[2], &range[1], sizeof(int)*( ArraySize-2 ) );
range[1] = newValue;


这篇关于如何在表[0]和表[1]之间插入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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