Actually there seems to be a few problems with this as there would be a lot of printf calls even when you follow Kennedy's advice.
Consider something like this:
Code:
#include <stdio.h>
void linearSearch (int numbers[], size_t size, int value)
{
/*
** Perform a linear search, that is, sequentially check every value
** in a group for a match
*/
int i;
int stpflg = 0;
for (i = 0; !stpflg && i < size; ++i)
{
if (numbers[i] == value)
{
stpflg = 1;
}
}
printf("Number%sfound after %d steps.\n", stpflg ? " " : " not ", i);
}
int main(void)
{
int numbers[] = { 42, 3, 6, 5, 2, };
size_t size = sizeof numbers / sizeof numbers[0];
linearSearch(numbers, size, 5); /* should be there */
linearSearch(numbers, size, 7); /* not supposed to be there */
return 0;
}
$ ./a.exe
Number found after 4 steps.
Number not found after 5 steps.