lately I have been asking questions a bit over my head so Im trying to break things down a little so I can understand it better.
What Im trying to do is look at all integers and if any of them are not 0-9 then return an error.
I was doing well with this earlier today but I have looked at so many different ways to code this that Im starting to confuse myself. I was curious if someone could please look at what I have and see where my mistake is?
Thank you
Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
int valid();
int main (void)
{
int a;
char buff[BUFSIZ];
printf("Enter number: ");
fgets(buff, BUFSIZ, stdin);
sscanf("%d", &a);
if( valid(buff, BUFSIZ, a))
printf("Output: %d\n", a);
else
printf("This is an error string\n");
getch();
}
int valid(int array[], int count, int a)
{
int i;
for (i = 0; i < count; i++)
{
if (array[a] >= 0 && array[a] <= 9)
return 1;
}
return 0;
}