View Single Post
Old 12-01-2006, 05:45 PM   #5 (permalink)
zero2
Junkie
 
zero2's Avatar
 
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.
zero2 is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76