Okay, here's a simplified version of my program:
Code:
/* INCLUDES */
#include <stdio.h>
int lookupTable(char dataCharacter1, char dataCharacter2);
char encodeB(int dataCharacter, int position);
main()
{
int i;
int inputB[4];
int outputB[120];
*outputB = 0;
/* test sequence 0367 */
inputB[0] = 0;
inputB[1] = 3;
inputB[2] = 6;
inputB[3] = 7;
for (i = 0; i <= ((int)(sizeof(inputB)) / 2); i++)
{
*outputB += lookupTable(inputB[i], inputB[i+1]);
i++;
}
printf((char *)outputB);
}
int lookupTable(char dataCharacter1, char dataCharacter2)
{
int encodation[20];
int j;
for (j = 0; j <= 8; j++)
{
encodation[j] = encodeB(dataCharacter1, j);
j++;
}
}
char encodeB(int dataCharacter, int position)
{
char bEncodation[2];
if (dataCharacter == 0)
{
if (position == 0)
{
*bEncodation = '0';
return *bEncodation;
}
else if (position == 2)
{
*bEncodation = '0';
return *bEncodation;
}
else if (position == 4)
{
bEncodation[0] = '0';
bEncodation[1] = '0';
return *bEncodation;
}
else if (position == 6)
{
bEncodation[0] = '0';
bEncodation[1] = '0';
return *bEncodation; }
else if (position == 8)
{
*bEncodation = '0';
return *bEncodation;
}
}
}
If you put a breakpoint on the line: encodation[j] = encodeB(dataCharacter1, j);
in the lookupTable function, and watch the values of encodation[j] change as you step through, you'll notice that for each even position (encodation[0], encodation[2], etc.) the value is 48 ('0'). However, the value for encodation[4] (and encodation[6]) needs to be '00'. How do I get the output to have 2 zeros rather than just 1? Do I not use an array in the function: char encodeB(int dataCharacter, int position) where I have the nested if statement:
Code:
else if (position == 4)
{
bEncodation[0] = '0';
bEncodation[1] = '0';
return *bEncodation;
}
? Any help is greatly appreciated and I can always post the full program if necessary (it shows what happens to the odd positions of encodation[j]...very similar). Thanks!