The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Trying to program a puzzle in C, need help finding the longest space for the word
Discuss Trying to program a puzzle in C, need help finding the longest space for the word in the C Programming forum on Dev Shed. Trying to program a puzzle in C, need help finding the longest space for the word C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 6th, 2013, 05:34 AM
|
|
Registered User
|
|
Join Date: Mar 2013
Posts: 1
Time spent in forums: 1 h 8 m 58 sec
Reputation Power: 0
|
|
|
Trying to program a puzzle in C, need help finding the longest space for the word
I am a newbie to C
I want to input a crossword puzzle in c and find the longest word that would fit into it.
I thought of creating the array something like below, where I can replace 1 with any letter.
char puzzle[6][4]={{'0', '1', '0', '0'},
{'0', '1', '0', '0'},
{'1', '1', '1', '1'},
{'0', '1', '0', '0'},
{'1', '1', '1', '1'},
{'0', '1', '0', '0'}};
I want to know if there is a way I can get the length of the longest word I can fill in. Like in above we can have the longest word in the 2nd column, but how do I write this in the program.
|

March 6th, 2013, 06:08 AM
|
 |
Contributed User
|
|
|
|
Code:
#include <stdio.h>
#include <stdlib.h>
int main ( ) {
char puzzle[6][4]={{'0', '1', '0', '0'},
{'0', '1', '0', '0'},
{'1', '1', '1', '1'},
{'0', '1', '0', '0'},
{'1', '1', '1', '1'},
{'0', '1', '0', '0'}
};
int r, c;
for ( r = 0 ; r < 6 ; r++ ) {
for ( c = 0 ; c < 4 ; c++ ) {
// scans each row
}
}
for ( c = 0 ; c < 4 ; c++ ) {
for ( r = 0 ; r < 6 ; r++ ) {
// scans each column
}
}
}
The test is basically
if ( puzzle[r][c] == '1' )
That's all there is to it, without giving the whole game away.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|