I'm going crazy. I'm writing a source that selects 5 poker cards from a shuffled deck and recognizes if there is a couple, double couple, tris and so on. However, the functions that deals with finding a Straight is giving me a hard time. I had to rewrite this because i haven't considered before the fact that the Ace can value 1 as well as 11. This is the source:
int hasStraight(const int wFirstFace[],int size)
{
int *firstfacePtr,i,j;
firstfacePtr=wFirstFace;
for(i=0;i<=1;i++)
{
for(j=0;j<=size-2;j++)
{
if (firstfacePtr[j]!=firstfacePtr[j+1]-1 && i==0)
break;
else if (firstfacePtr[j]!=firstfacePtr[j+1]-1 && i==1)
return 0;
else if (j==3 &&firstfacePtr[j]==firstfacePtr[j+1]-1)
printf("Scala!\n");
return 1;
}
if (firstfacePtr[0]==0)
firstfacePtr[0]=13;
bubble(firstfacePtr,size); /*bubble goes through an array
and put it in ascending order*/
}
}
Notes: wFirstFace
is an array containing 5 integers; size is an integer, and it's equal to 5.
I have tried to declare wFirstFace={0,1,2,3,4}
in order to check if the code worked or not.
Then, the internal 'for' cycle ends after one cycle, and the function returns a 0 and I don't even know why or where.
Where did I make a mistake in this messy source code?