Output of a void function

Asked

Viewed 265 times

0

I’m programming a word hunt and a problem in the void function is making it difficult. In the code I use functions to scan the matrix in all directions and returns me the initial and final coordinates or leave the function and start reading in another direction, there is my doubt, it is possible to leave the function, as I indicated with #######, or do an int function with Return 0? Help me with this code and if you see another error in the code signal me.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

void Norte (char cacapalavra[][100], char palavra[], int pc, int pl) {
    int i, j, n, k;
    j = pc; k = 0;
    n = strlen(palavra);

    for (i = pl; i < i+n; i++) {
            if (cacapalavra [i][j] != palavra[k]) ######;
            else k++;
    }
    printf ("%d %d", pc, pl);
    printf("%d %d", i, j);
}

void Sul (char cacapalavra[][100], char palavra[], int pc, int pl) {
    int i, j, n, k;
    j = pc; k = 0;
    n = strlen(palavra);

    for (i = pl; i < i+n; i++) {
            if (cacapalavra [i][j] != palavra[k]) #####;
            else k++;
    }
    printf ("%d %d", pc, pl);
    printf("%d %d", i, j);
}

void Leste (char cacapalavra[][100], char palavra[], int pc, int pl) {
    int i, j, n, k;
    i = pl; k = 0;
    n = strlen(palavra);

    for (j = pc; j < j+n; j++) {
            if (cacapalavra [i][j] != palavra[k]) #####;
            else k++;
    }
    printf ("%d %d", pc, pl);
    printf("%d %d", i, j);
}

void Oeste (char cacapalavra[][100], char palavra[], int pc, int pl) {
    int i, j, n, k;
    i = pl; k = 0;
    n = strlen(palavra);

    for (j = pc; j < j+n; j--) {
            if (cacapalavra [i][j] != palavra[k]) #####;
            else k++;
    }
    printf ("%d %d", pc, pl);
    printf("%d %d", i, j);
}

void Nordeste (char cacapalavra[][100], char palavra[], int pc, int pl) {
     int i, j, n, k;
     k = 0;
     n = strlen(palavra);

     for (i = pl, j = pc; i < i+n; j++, i--) {
             if (cacapalavra [i][j] != palavra[k]) #####;
            else k++;
     }
     printf ("%d %d", pc, pl);
     printf("%d %d", i, j);
}

void Noroeste (char cacapalavra[][100], char palavra[], int pc, int pl) {
     int i, j, n, k;
     k = 0;
     n = strlen(palavra);

     for (i = pl, j = pc; i < i+n; j--, i--) {
            if (cacapalavra [i][j] != palavra[k]) #####;
            else k++;
    }
    printf ("%d %d", pc, pl);
    printf("%d %d", i, j);
}

void Sudeste (char cacapalavra[][100], char palavra[], int pc, int pl) {
     int i, j, n, k;
     k = 0;
     n = strlen(palavra);

     for (i = pl, j = pc; i < i+n; j--, i++) {
             if (cacapalavra [i][j] != palavra[k]) #####;
             else k++;
     }
    printf ("%d %d", pc, pl);
    printf("%d %d", i, j);
}

void Sudoeste (char cacapalavra[][100], char palavra[], int pc, int pl) {
     int i, j, n, k;
     k = 0;
     n = strlen(palavra);

     for (i = pl, j = pc; i < i+n; j++, i++) {
             if (cacapalavra [i][j] != palavra[k]) ######;
             else k++;
     }
     printf ("%d %d", pc, pl);
     printf("%d %d", i, j);
}

int main () {

    char cacapalavra [100][100];
    char palavra [100];
    int i, j, k, n, pc, pl;
    k = 0;

    scanf ("%d", &n);

    for (i = 0; i < n; i++)
          for (j = 0; j < n; j++)
                scanf ("%c", &cacapalavra[i][j]);

    scanf ("%s", palavra);

    for (i = 0; i < n; i++) {
          for (j = 0; j < n; j++) {
                if (palavra[k] == cacapalavra[i][j]) {
                pc = j; pl = i;
                Norte(cacapalavra, palavra, pc, pl);
                Sul(cacapalavra, palavra, pc, pl);
                Leste(cacapalavra, palavra, pc, pl);
                Oeste(cacapalavra, palavra, pc, pl);
                Nordeste(cacapalavra, palavra, pc, pl);
                Noroeste(cacapalavra, palavra, pc, pl);
                Sudeste(cacapalavra, palavra, pc, pl);
                Sudoeste(cacapalavra, palavra, pc, pl);

               }
         }
    }
    return 0;
}
  • 2

    Marcelo you managed to solve?

  • Not completely Lais, I haven’t got my positions right yet, my program is only reading part of the words.

1 answer

4

To abandon a function that returns void halfway through, uses return

        if (cacapalavra [i][j] != palavra[k]) return;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.