Solved

# LOOP NOT LOOPING

Posted on 2003-02-23
Medium Priority
364 Views
can anyone tell me whats wrong with this loop? it executes once but it does not repeat what its supposed to do...(search the word search puzzle diagonally at the upper part)... pls help me! tnx!

for(l2=1; l2<=cols; l2++)
{
lastcc = l2;

for(l1 = 1; l1<=rows; l1++)
{
rowc = l1;
ctr = 1;

if(l1 = 1)
{
colc = l2;
}

else
{
lastcc++;
colc = lastcc;
}

while((ctr <= sl) && (rowc<=rows) && (colc<=cols))
{
cword[ctr-1]=puzzle[rowc-1][colc-1];
rowc++;
colc++;
ctr++;
}

for (z=0;z<=strlen(sword)-1;z++)
{
lsword[z]=tolower(sword[z]);
}

for (z=0;z<=strlen(cword)-1;z++)
{
lcword[z]=tolower(cword[z]);
}

if (strcmp(lcword, lsword) == 0)
{
for(b=l1, c=l2; (b<=l1+sl-1)&& (c<=l2+sl1);      b++, c++)
{
found = 0;
printf("\t%c (%d,%d)", puzzle[b-1][c-1], b, c);
printf("\n");
}
}

}//for l1

}//for l2

if(found != 0)
{
}
0
Question by:arabo
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 2

Accepted Solution

grue earned 200 total points
ID: 8002540
Which loop? :)

I see one problem:

if(l1 = 1)

I don't think you want that to be an assignment.  You probably want:

if(l1 == 1)

I didn't walk through the logic of your function because I don't know what its goal is...  If you explain what your goal is maybe other problems might manifest themselves...

For instance, is it necessary to have:

for (z=0;z<=strlen(sword)-1;z++)
{
lsword[z]=tolower(sword[z]);
}

so deep inside your loops?  Looks like you do it over and over and over again unnecessarily.

Also, you should probably be null terminating your cword string:

cword[ctr-1]=puzzle[rowc-1][colc-1];
cword[ctr] = '\0';  // add this

if you're going to be using strcmp() on the string.
0

Author Comment

ID: 8002707
i do not know which loop it stops...but the goal is... to search a word in a word search puzzle...my program already works when it comes to searching vertically and horizontally...the one i posted is just one part of the diagonal search...it would search from left to right... upper part of the puzzle... i followed your tip of making if(l1=1) to if(l1 == 1)...it loops now but the new problem is...it prints out letters it shouldn't be printing... here is an example...

if this is the puzzle...

ab
de

and i want to search for... 'ae', and 'b'....

it would say...

"ae" --> a(1,1) e(2,2) <-- (row, column)

the first one is always correct..but when it goes to the second one it becomes...

"b" ---> b(1,2) e(2,2)

...'e' shouldn't be included...but it still prints it...

0

Author Comment

ID: 8002719
the only problem is when i search for the letter in the corner...

if this is the word search puzzle

a b c d e
f g h i j
k l m n o

if search for the letter 'e'...it would print...

e(3,5)
j(4,5)
o(5,5)

...it prints the last column...
0

LVL 20

Expert Comment

ID: 10014706
Nothing has happened on this question in over 10 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by grue (even if it is homework).

jmcg
EE Cleanup Volunteer
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
###### Suggested Courses
Course of the Month13 days, 10 hours left to enroll