Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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];
Posted
Updated 19-Nov-17 14:06pm
v4
Comments
Rick York 17-Nov-17 18:07pm    
I think you omitted some of your code there.

This has lots of problems. You have arrays of size 256 and you are accessing item 257 in it. In the C language, the indexes of those array will range from 0 to 255, or one less than their capacity since they start at zero. I always make a "magic" value like that into a const value in C++ or a definition C. An example is :

#define ArraySize 256

int range[ArraySize];
// using it in a loop :
for( c = 0; c < ArraySize; ++c )
{
range[c] = 0;
}
yagami_md 18-Nov-17 5:53am    
Your solution is only what I did for counted the all char in the file but in the table headcOunt[]
My problem is how I insert a new symbol(char) before the 0 symbol and try to insert the symbol in the range[] table and the range of the symbol will be between the range[0] and range[1]
It means range[plus(val)]=1
Range [moins(val)]=0
Richard MacCutchan 18-Nov-17 6:40am    
That is certainly strange looking C code: reserved (and other) words starting with capital letters.
yagami_md 18-Nov-17 7:18am    
How I can I do it??
Richard MacCutchan 18-Nov-17 12:07pm    
I am not sure I understand the question. I certainly don't understand the code.

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.
 
Share this answer
 
Here is one way to move an array down and insert a new value :

C++
#define ArraySize 256
int range[ArraySize];
memmove( &range[2], &range[1], sizeof(int)*( ArraySize-2 ) );
range[1] = newValue;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900