This question regards another exercise from my book.
I have this rather dull program that is supposed to report back as "True" if it finds a 0 contained in the array, or "False" if there are no zeros.
Instead, the program is is reporting back "1" for true, or "0" for false.
I can't figure out how to get it working. I think it has something to do with the %d (int) conversion specifier in the printf line. (Highlighted in orange). I don't suppose %c works either, since that's a single character.
We haven't gotten to strings yet in the book. Is there a conversion spec for strings that will properly printing out True or False?
Code:
#include <stdio.h>
#define TRUE 1
#define FALSE 0
typedef int Bool;
Bool has_zero(int a[], int n);
int main(void)
{
int i;
int a[10] = { 1, 0, 8, 20, 12, 27, 1, 32, 12, 10 };
printf("Zero found: %d\n", has_zero(a, 10));
return 0;
}
Bool has_zero(int a[], int n)
{
int i;
for (i = 0; i < 10; i++)
if (a[i] == 0)
return TRUE; /* Will return from the function when a zero element is found */
return FALSE; /*Can only be reached if all elements are non zero */
}