4
I’m doing a program that hunts a word from a matrix. For this I made 8 functions that sweep 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 "home" in the matrix, the program returns the coordinates of the letter 'c' and the letter 'a' (last letter), as the entries I have and I need two values in the output.
I used pointers as parameters, only it is giving much Warning. Still missing to finish the complete code.
#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)) ===|
Which ones warnings? Where?
– Maniero
At the end "Warning: Passing argument 3 of 'Norte' from incompatible Pointer type|", I know it’s the pointer passage, but I don’t know how to get it out. I’m running on codeblocks
– Marcelo de Sousa
The edition had hidden them. There is a lot of error in this code, it will be dicífil find all. And the worst, that even though Compile, I will never trust him without making a thorough assessment. There are things I don’t even know how to fix, I’d have to understand what all the code does to solve. An example is that the function does not return anything in certain situations. It has to return, but what?
– Maniero
From what I understand the warnings are of passing pointer to function, all functions are very similar.
– Marcelo de Sousa
This is just a problem, this you solve by passing the variables without
&
. I’m talking about this at http://answall.com/q/125793/101 Part of the problem is the code is disorganized, some things are not easy to see.– Maniero
Did the answer solve your problem? Do you think you can accept it? If you don’t know how you do it, check out [tour]. This would help a lot to indicate that the solution was useful to you and to give an indication that there was a satisfactory solution. You can also vote on any question or answer you find useful on the entire site.
– Maniero
The error is time to pass the parameters, for example to the "North". This variable is already a pointer to "int", so you can’t put the "&" on pc in front, otherwise you’ll be interpreting the pointer as a pointer.
– Ivan Ferrer
Try declaring: int **pc, if you want pointer pointer
– Ivan Ferrer