How do I read these warnings

2

I'm doing a program that hunts a word from within an array. For this I did 8 functions that scan in all regions, as I need to return in the output the coordinates of the first and last letter.

For example, I need to find the word "house" in the array, the program returns the coordinates of the letter 'c' and the letter 'a' (last letter), as the entries I have and need two values in the output.

I used pointers as parameters, but it's giving a lot of warning. The complete code is still missing.

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

int 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]) return -1;
            else k++;
    }
    *pl = i;
}

int 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]) return -1;
            else k++;
    }
    *pl = i;
}

int 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]) return -1;
            else k++;
    }
    *pc = j;
}

int 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]) return -1;
            else k++;
    }
    *pc = j;
}

int 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]) return -1;
            else k++;
     }
     *pl = i; *pc = j;
}

int 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]) return -1;
            else k++;
     }
     *pl = i; *pc = j;
}

int 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]) return -1;
             else k++;
     }
     *pl = i; *pc = j;
}

int 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]) return -1;
             else k++;
     }
     *pl = i; *pc = j;
}

int main () {

    char cacapalavra [100][100];
    char palavra [100];
    int i, j, k, n, *pc, *pl, aux;
    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;
                aux = Norte(cacapalavra, palavra, &pc, &pl);
                aux = Sul(cacapalavra, palavra, &pc, &pl);
                aux = Leste(cacapalavra, palavra, &pc, &pl);
                aux = Oeste(cacapalavra, palavra, &pc, &pl);
                aux = Nordeste(cacapalavra, palavra, &pc, &pl);
                aux = Noroeste(cacapalavra, palavra, &pc, &pl);
                aux = Sudeste(cacapalavra, palavra, &pc, &pl);
                aux = Sudoeste(cacapalavra, palavra, &pc, &pl);
                }
          }
    }
}

Warnings:

||=== Build file: "no target" in "no project" (compiler: unknown) ===|
C:\Users\mdesousa\Documents\cacapalavra.c||In function 'main':|
C:\Users\mdesousa\Documents\cacapalavra.c|120|warning: passing argument 3 of 'Norte' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|5|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|120|warning: passing argument 4 of 'Norte' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|5|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|121|warning: passing argument 3 of 'Sul' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|17|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|121|warning: passing argument 4 of 'Sul' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|17|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|122|warning: passing argument 3 of 'Leste' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|29|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|122|warning: passing argument 4 of 'Leste' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|29|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|123|warning: passing argument 3 of 'Oeste' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|41|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|123|warning: passing argument 4 of 'Oeste' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|41|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|124|warning: passing argument 3 of 'Nordeste' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|53|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|124|warning: passing argument 4 of 'Nordeste' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|53|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|125|warning: passing argument 3 of 'Noroeste' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|65|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|125|warning: passing argument 4 of 'Noroeste' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|65|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|126|warning: passing argument 3 of 'Sudeste' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|77|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|126|warning: passing argument 4 of 'Sudeste' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|77|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|127|warning: passing argument 3 of 'Sudoeste' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|89|note: expected 'int *' but argument is of type 'int **'|
C:\Users\mdesousa\Documents\cacapalavra.c|127|warning: passing argument 4 of 'Sudoeste' from incompatible pointer type|
C:\Users\mdesousa\Documents\cacapalavra.c|89|note: expected 'int *' but argument is of type 'int **'|
||=== Build finished: 0 error(s), 16 warning(s) (0 minute(s), 0 second(s)) ===|
    
asked by anonymous 27.09.2016 / 22:57

1 answer

3

I've arranged the variables that were being sent with & and are already pointers . I put returns on the functions (I kicked a value just to end with warning ), I made use of the aux variable and assign values to the variables pc and pl . I doubt that I should do what I should, but I solved the problem described in the question, if the question has more details I will improve.

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

int 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]) return -1;
            else k++;
    }
    *pl = i;
    return 0;
}

int 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]) return -1;
            else k++;
    }
    *pl = i;
    return 0;
}

int 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]) return -1;
            else k++;
    }
    *pc = j;
    return 0;
}

int 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]) return -1;
            else k++;
    }
    *pc = j;
    return 0;
}

int 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]) return -1;
            else k++;
     }
     *pl = i; *pc = j;
     return 0;
}

int 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]) return -1;
            else k++;
     }
     *pl = i; *pc = j;
     return 0;
}

int 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]) return -1;
             else k++;
     }
     *pl = i; *pc = j;
     return 0;
}

int 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]) return -1;
             else k++;
     }
     *pl = i; *pc = j;
     return 0;
}

int main () {

    char cacapalavra [100][100];
    char palavra [100];
    int i, j, k, n, *pc = 0, *pl = 0, aux;
    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;
                aux = Norte(cacapalavra, palavra, pc, pl);
                aux = Sul(cacapalavra, palavra, pc, pl);
                aux = Leste(cacapalavra, palavra, pc, pl);
                aux = Oeste(cacapalavra, palavra, pc, pl);
                aux = Nordeste(cacapalavra, palavra, pc, pl);
                aux = Noroeste(cacapalavra, palavra, pc, pl);
                aux = Sudeste(cacapalavra, palavra, pc, pl);
                aux = Sudoeste(cacapalavra, palavra, pc, pl);
                printf("%d", aux); //só para eliminar o warning que não foi usada.
                }
          }
    }
}

See compiling on ideone .

    
27.09.2016 / 23:24