So you're actually looking for consecutive numbers, not searching for particular numbers. If that's the case, you are realling just wanting to check if the digit before is equal to one less than the current digit, and that that occurs 3 times in a row:
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int consec(char *);
int main()
{
char a[][6] = { "52915", "12394", "34560", "12345", "82345", "23459", "67923", "12356", "43210", "90125" };
int i;
for (i = 0; i < sizeof(a)/sizeof(a[0]); i++)
printf("%s: %d\n", a[i], consec(a[i]));
return 0;
}
int consec(char *s)
{
int i;
int conseccount = 0;
if (!s || strlen(s) < 4)
return -1; /* invalid input */
for (i = 1; i < strlen(s); i++)
{
if (!isdigit(s[i]))
return -1; /* invalid input */
if (s[i-1] == s[i]-1)
{
conseccount++;
if (conseccount == 3)
return 1;
}
else
conseccount = 0;
}
return 0;
}
Output:
Code:
52915: 0
12394: 0
34560: 1
12345: 1
82345: 1
23459: 1
67923: 0
12356: 0
43210: 0
90125: 0
Of course, you could trivially make consec() generic to check for n consecutive numbers, or report the maximum consecutive run it finds.