mercredi 14 janvier 2015

C: How can I recursively compute each side of a specific character?

I'm working in C. The program will tell the user what kind of formula is entered.



int foo(char* x, char* y)
{


[Code here will return >0 if fmla not starting with 'l' is valid]



if (x[0] == 'l')
{
char* location = x + strcspn(x, "ijk");
if (foo(x+1, y-1) > 0 && foo(location+1, y-1) > 0)
{
printf("valid");
}
else
{
printf("not valid");
}
}
}


The if (x[0] == 'l') loop recursively computes input each side of 'location.' When the program runs through the loop, it will always show invalid even if the input is valid.


Could anyone help me out?


Thanks!


Aucun commentaire:

Enregistrer un commentaire