Word Search using Multidimensional arrays
<p>This program is supposed to allow the user to enter a word to be searched for in a multi-dimensional array filled with characters. The word can be in any non-diagonal direction. </p>

<p>As it is written it will only find the correct location for a one character long word. I understand that it will only find the first instance of any word entered but that is okay. I cannot figure out why it will not find words longer than one character.</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;ctype.h&gt;
#include &lt;time.h&gt;
#include &lt;string.h&gt;

#define GRIDSIZE 10
#define MAXSIZE 15   //Max size for word to search
#define SENTINEL -1

void print_grid(int[][GRIDSIZE], int);
int search_grid(int[][GRIDSIZE], int, int[], int, int[], int[]);

int main(void){
    int grid[GRIDSIZE][GRIDSIZE];
    int grid_size;
    char word[MAXSIZE];
    int word_int[MAXSIZE];
    int a,b,i,j,h;
    int word_size;
    int word_found;
    int go_again;
    int location_row[word_size];
    int location_column[word_size];

    srand(time(NULL));

    //fills grid with random letters
    for(i=0; i&lt;10; i++){
        for(j=0; j&lt;10; j++){
            do{grid[i][j] = rand() %  123;
            }while(grid[i][j]&lt;97);
        }}


    //gets word and searches for it, returns 1 or 0 for found or not
    //exits of sentinel is entered
    do{
    print_grid(grid, grid_size);
    printf("Please enter a word to search followed by 'ENTER':\n");
    scanf(" %s", word);

    word_size = strlen(word);

    for(b=0; b &lt; word_size; b++){
        word_int[b] = word [b];
    }

    word_found = search_grid(grid, grid_size, word_int, word_size, location_row, location_column);
    ("%d", word_found);

    if(word_found == 0){
        printf("\nThe word you entered was not found\n");
        printf("Enter '1' to search for another word, or '0' to exit, followed by 'ENTER'\n");
        scanf(" %d", &amp;go_again);
    }

    }while(word_found != 1 &amp;&amp; go_again == 1);



    if(word_found == 1){
        printf("The word you entered was found at:\n");
        for(h=0; h &lt; word_size; h++){
            printf("%c%d: ", toupper(location_row[h] + 97), location_column[h]+1);
        }
        print_grid(grid, grid_size); 
    }

    return 0;
}

//prints N*N grid with labels on each axis
void print_grid(int grid[][GRIDSIZE], int grid_size){
    int i,j,k;
    char row[26] ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    printf("\n");

printf("   ");
for(k=1; k &lt; GRIDSIZE +1; k++){
            printf("%d ", k);}

printf("\n");

for(i=0; i&lt;10; i++){
    printf("%-c  ", row[i]);
        for(j=0; j&lt;10; j++){
            printf("%-c ", grid[i][j]);
        }
    printf("\n");
}
printf("\n");
    return;
}

//searches grid for word
int search_grid(int grid[][GRIDSIZE], int gride_size, int word_int[], int word_size, int location_row[], int location_column[]){
    //printf("SEARCH GRID RAN//////////////////////");

    int r, c, q;
    int num = 0;
    int found[word_size];
    int found_total = 0;


    for(q=0; q &lt; word_size; q++){
        found[q] = 0;}

    //search loops
    for(r=0; r &lt; GRIDSIZE; r++){
        for(c=0; c &lt; GRIDSIZE; c++){
            if(grid[r][c] == word_int[num]){
                found[num] = 1;
                location_row[num] = r;
                location_column[num] = c;
                    for(num=1; num &lt; word_size; num ++){
                        if(r=0){
                        if(c=0){
                            if(grid[location_row[num-1]][location_column[num-1]+1] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]+1][location_column[num-1]] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                    //CHECK DOWN AND RIGHT
                        }
                        if(c = GRIDSIZE - 1){
                            if(grid[location_row[num-1]][location_column[num-1]-1] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]][location_column[num-1]+1] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]+1][location_column[num-1]] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                    //CHECK DOWN AND LEFT
                        }
                        else{
                            if(grid[location_row[num-1]][location_column[num-1]-1] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]][location_column[num-1]+1] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]+1][location_column[num-1]] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                    //CHECK LEFT RIGHT DOWN
                        }
                    }
                        if(r = GRIDSIZE - 1){
                        if(c=0){
                            if(grid[location_row[num-1]][location_column[num-1]+1] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]-1][location_column[num-1]] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                    //CHECK up AND RIGHT
                        }
                        if(c = GRIDSIZE - 1){
                            if(grid[location_row[num-1]][location_column[num-1]-1] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]-1][location_column[num-1]] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                    //CHECK UP AND LEFT
                        }
                        else{
                            if(grid[location_row[num-1]][location_column[num-1]-1] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]][location_column[num-1]+1] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]-1][location_column[num-1]] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                    //CHECK LEFT RIGHT UP
                        }
                    }
                        else{
                        if(c=0){
                            if(grid[location_row[num-1]-1][location_column[num-1]] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]+1][location_column[num-1]] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]][location_column[num-1]+1] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                    //CHECK UP DOWN AND RIGHT
                        }
                        if(c = GRIDSIZE - 1){
                            if(grid[location_row[num-1]-1][location_column[num-1]] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]+1][location_column[num-1]] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]][location_column[num-1]-1] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                    //CHECK UP DOWN AND LEFT
                        }
                        else{
                            if(grid[location_row[num-1]][location_column[num-1]-1] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]][location_column[num-1]+1] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]-1][location_column[num-1]] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                            if(grid[location_row[num-1]+1][location_column[num-1]] == word_int[num])
                                found[num] = 1;
                                location_row[num] = r;
                                location_column[num] = c;
                    //CHECK LEFT RIGHT UP DOWN
                        }
                    }
                }
            }
        }
    }


    for(q=0; q &lt; word_size; q++){
        found_total += found[q];
    }
    //printf("FOUND TOTAL %d", found_total);

    if(found_total == word_size){
           return 1;
        }

    if(found_total != word_size){
        return 0;
}
}
</code></pre>