humpty


Group: Members
Posts: 655
Joined: Sep. 2005 |
 |
Posted: Jan. 13 2008,16:05 |
 |
yeh, wdef's code is somewhat similar to some c code i used before to generate strings; just change MAX to 30 and the 'check' routine.
Code Sample | #include <stdio.h>
#define MAX 4
int check (char *s) { printf ("%s\n", s); if (!strcmp (s, "help")) return (1); return (0); } //-------------------------------------- char s[MAX+1];
int try_again (int pos) { char c;
s[pos+1]='\0';
for (c='a'; c<'z'+1; c++) { s[pos] = c; if (check (s)) return(1); //success!
if (pos == MAX-1) continue; if (try_again (pos+1)) return(1); } return (0); } //-------------------------------------- int main () { if (try_again (0)) printf ("cracked :)\n"); else printf ("failed :(\n"); }
|
the trick is to recurse, but to also use a global var so you don't blow the stack memory!
|