Your understanding of the removeArray is not correct.
removeArray is set up as a 256 array set, which conforms to the possible values of one byte. One byte = 2 to the power 8, = 256. Thus, the possible values of a byte is 0 to 255, or 0x00 to 0xFF.
The removeArray merely is a lookup template. Since we know that we wish to remove letters 'e', 'o', 'r', and 'd', these translate to the ascii values 101, 111, 114, and 100. Thus the removeArray gets set up with 256 zeros, and in position 101, the value is 1. Eg. positions 109 to 115 will look like : ... 0,0,1,0,0,1,0 ....
Now, when we read our string, we check the character against this template. If it is set to 1, (or true), we do not copy it to the string, but simply read over it to the next character.
Strangely, though, in your example of the frequency, the template set up is in fact, correct!!!. However, note that the the frequency array index corresponds to the grade, and the contents at the index the frequency itself. It differs in the logic of the removeArray, but the concept of the template still holds true.
BTW, I must admit that this code is really crappy. Today, a developers time is MORE valuable than memory or CPU processing speed; thus, always write easy to read maintainable code!
#include <stdio.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
char *RemoveChars( char *src
, char *key )
{
char *dest;
size_t len_src;
size_t len_key;
int found;
int i;
int j;
int k;
/*
** Initialise
*/
i = 0;
j = 0;
k = 0;
len_src = 0;
len_key = 0;
dest = NULL;
len_src = strlen( src );
len_key = strlen( key );
/*
** Allocate memory for the destination and initialise it
*/
dest = (char *) malloc( sizeof( char ) * len_src + 1 );
if ( NULL == dest )
{
printf("Unable to allocate memory\n");
// DO EXCEPTION HANDLING HERE
}
memset( dest, 0x00, sizeof( char ) * len_src + 1 );
/*
** MAIN LOOP. For each character in the source, we check against the key.
** We use the 'found' boolean to evaluate whether we need to copy or not.
*/
for ( i = 0; i < len_src; i++ )
{
found = FALSE;
for ( j = 0; j < len_key; j++ )
{
if ( src[i] == key[j] )
found = TRUE;
}
/*
** Copy the character if it was NOT found in the key
*/
if ( FALSE == found )
{
dest[k] = src[i];
k++;
}
}
/*
** Return the destination pointer to the main function
*/
return ( dest );
}
void main()
{
char string[] = "Hello World";
char remove[] = "eord";
char *result = NULL;
result = RemoveChars( string
, remove );
printf( "The result is %s\n", result );
}