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

    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    Making a word search in C


    This is what I would think but I am a beginner. I've tried to create a simple 5 by board but am having some trouble. After which I want to create a function which allows the user to try and find the hidden words. If the user is correct, then the word can change to something else. Try to make it as simple as possible. For simplicity, in this example the hidden words are CAT, DOG AND CAR.

    #include <stdio.h>
    #include <stdlib.H>
    #define ROWS 5
    #define COLS 5

    char board[ROWS][COLS];
    int i,j;

    void table();
    void printtable();

    int main()
    {
    table();
    printtable();

    getchar();
    return 0;

    }

    void table()
    {
    char board[ROWS][COLS] = {

    'A','B','C','A','R',
    'F','G','A','I',' J',
    'K','L','T','N','O',
    'P','Q','R','S','T',
    'U','V','D','O','G',
    };

    int i,j;
    for(i = 0; i < ROWS; i++){
    for(j = 0; j < COLS; j++)
    board[ROWS][COLS];
    }
    }

    void printtable()
    {
    int i,j;
    for(i = 0; i < ROWS; i++){
    for(j = 0; j < COLS; j++)
    board[ROWS][COLS];
    }

    }

    Any help would be appreciated.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    It looks like you wanted at the very least to display the board. This version does. You'll need to show examples of "changing" for anyone like me* to understand what you mean. File name c.c, compilation and execution on unix** could be:

    $ gcc -Wall c.c -o c.exe
    $ ./c.exe
    Code:
    #include <stdio.h>
    #include <stdlib.H>
    
    #define ROWS 5
    #define COLS 5
    
    void printtable(char t[ROWS][COLS]) {
      int i,j;
      char*pc;
      for(i = 0; i < ROWS; i++) {
        pc = t[i];
        for(j = 0; j < COLS; j++)
          putchar(' '), putchar(pc[j]);
        putchar('\n');
      }
      fflush(stdout);
    }
    
    static char board[ROWS][COLS] = {
      "ABCAR",
      "FGAIJ",
      "KLTNO",
      "PQRST",
      "UVDOG"
    };
    
    int main() {
      printtable(board);
      getchar();		       /* fix your command line interpreter */
      return 0;
    }
    *here "like me" means "doesn't understand you".
    **I'm using bash with mingw on a Windows7 system.
    Last edited by b49P23TIvg; December 12th, 2013 at 05:23 PM. Reason: simplification
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo