Thanks for getting me started, I came up with a solution to my problem:
Code:
#include <stdio.h>
#define MAX 20
void printInfo(void);
int extractInfoVerB(char[], int, int[]);
int main ()
{
int iSize;
char cAryInputOld[20] = { '1', '0', '0', '1', '1', '0', '0',
'0', '1', '0', '0', '0', '0', '2',
'a', '0', 's', '1', '4', 'e' };
int iBinaryAryOld[24] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
iSize = MAX;
printInfo();
extractInfoVerB(cAryInputOld, iSize, iBinaryAryOld);
return 0;
}
void printInfo(void)
{
printf("Exercise #2\n");
printf("zero2\n\n");
return;
}
int extractInfoVerB(char cAryInputOld[], int iSize, int iBinaryAryOld[])
{
int i, j, iTmp, iVal;
j = 0;
for (i = 0; i < iSize; i++)
{
if (cAryInputOld[i] == '0' || cAryInputOld[i] == '1')
{
iBinaryAryOld[j] = cAryInputOld[i] - 48;
j++;
}
}
iTmp = 0;
// # of occurences of 0
for ( i = 0; i < iSize; i++)
{
if (iBinaryAryOld[i] == 0)
{
iTmp = iTmp + 1;
}
}
iBinaryAryOld[iSize + 0] = iTmp;
iTmp = 0;
// # of occurences of 1
for ( i = 0; i < iSize; i++)
{
if (iBinaryAryOld[i] == 1)
{
iTmp = iTmp + 1;
}
}
iBinaryAryOld[iSize + 1] = iTmp;
iTmp = 0;
//# of occurences of pattern 11
for ( i = 0; i < iSize; i++)
{
if (iBinaryAryOld[i] == 1 && iBinaryAryOld[i+1] == 1)
{
iTmp = iTmp + 1;
}
else i = i + 2;
}
iBinaryAryOld[iSize + 2] = iTmp;
iTmp = 0;
//# of occurences of pattern 01
for (i = 0; i < iSize; i++)
{
if (iBinaryAryOld[i] == 0 && iBinaryAryOld[i+1] == 1)
{
iTmp = iTmp + 1;
}
}
iBinaryAryOld[iSize + 3] = iTmp;
iTmp = 0;
printf("Given the array of characters:\n ");
for (i = 0; i < iSize; i++)
{
printf("%c", cAryInputOld[i]);
}
printf("\nThere is/are %d character (s) in the given array.\n\n", iSize);
printf("Array of binary information: \n [");
for ( i = 0; i < iSize + 4; i++ )
{
printf("%3d", iBinaryAryOld[i]);
}
printf(" ]");
if( iBinaryAryOld[iSize] != 0 || iBinaryAryOld[iSize + 1] != 0 )
{
iVal = 1;
printf("\n\nThere is at least one character digit (0 or 1) stored in the array.");
}
else
{
iVal = 0;
}
return iVal;
}