Code:
/**
* Program Name: --
*
*/
#include <stdio.h>
#define MAX 10
void extractInfo(char[],int, int[]);
int main()
{
char cInputOld[10] = { 'a', '1', 'r', 'o', '0', 'm', 'y', '1', 'i', 'b' };
int iBinary[13] = { -1 } ;
int iSize;
iSize = MAX;
extractInfo(cInputOld, iSize, iBinary);
return 0;
}
void extractInfo(char cInputOld[], int iSize, int iBinary[])
{
int i, j;
printf("Given the array of characters:\n");
for( i = 0; i < iSize; i++)
{
printf("cInputOld[%d] = %c", i, cInputOld[i]);
printf("\n");
}
j = 0;
printf("Array of binary digits:\n");
for ( i = 0; i < iSize; i++)
{
if (cInputOld[i] == '0'|| cInputOld[i] == '1')
{
iBinary[j] = cInputOld[i] - 48;
j++;
}
}
for( j = 0; j < 13; j++)
{
printf("%3d", iBinary[j]);
}
return;
}
After this recent update, now I want the output to look like the following:
1 0 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
I thought if I initialized the iBinary upfront:
iBinary[13] = { -1 }; it should assign the value of -1 to all indices.
btw thank you everyone for your help.