#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep 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.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo