Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple For Loop

Status
Not open for further replies.

Jmareky

Technical User
Nov 22, 2006
2
0
0
US
I have this piece of code:

placeword(char *wordpointer,char puzzlespace[60][60],int dumbarray[2])
{
int length=0,i=0,q=0,xandyarray[2];
while(word[length]!=0)
{
length++;
}

//This is the for loop in question

for(i=0;i>100;i++)
{
int randomx=(rand()%(dumbarray[0]+1)),randomy=(rand()%(dumbarray[1]+1));
xandyarray[0]=randomx;
xandyarray[1]=randomy;
int a=checkhoriz(word,puzzlespace,xandyarray),b=checkvert(word,puzzlespace,xandyarray);
if((puzzlespace[randomx][randomy]==BLANK)&&((randomx+length)<=dumbarray[0])&&(a==1))
puzzlespace[randomx][randomy]=puts(word);
if((puzzlespace[randomx][randomy]==BLANK)&&((randomy+length)<=dumbarray[1])&&(b==1))
{
for(q=0;word[q]==0;q++)
{
puzzlespace[randomx][randomy+q]=word[q];
}
}
return;
}
}

It is rather simple, but the For loop is skipped during testing. I ran it step by step, and the program reaches the loop and skips to two lines past the return;. I don't know what is causing this. i=0, and the other For loops in my program work, just not this one.
 
Yes, it is a typo. The i>100 should be i<100. Thank you for pointing that out.
 
Which for loop isn't working, the i loop or the q loop? For one thing, if the typo above is the only typo, you have the return statement at the end of the "for i" loop. That means it will only go through that code block the first time, then return from the function. Maybe you should put the return statement after the second to last closing bracket.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top