'passing argument 1 of 'print' from incompatible pointer type [-Werror=incompatible-pointer-types]
First, I have to say that I just started learning pointers, so I'm kind of lost. My professor told me to make a program which reads names, ages, antiquity and docket of X quantity of people, and when it's done, print it on a table-like format. For all of that, I have to have 2 separate functions. One that reads what the user inputs, and other that outputs everything the user inputted in a table like format.
Now, the problem is that I cannot pass my 3D array to the printt() function. The idea is that I don't pass the whole array, instead I just pass the memory address (using &) and then I reference that memory address to all my printf()s (using *).
Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define sfb if(db[i][0][0] == 17 || db[i][1][0] == 17 || db[i][2][0] == 17 || db[i][3][0] == 17){break;}
void read();
void printt(char *dbp);
int main(){
read();
}
void read(){
char db[20][3][20];
printf("Ingrese ^Q para salir\n");
for(int i = 0; i <= 20; i++){
printf("Ingrese nombre de persona: ");
fgets(db[i][0], sizeof db[i][0], stdin);
db[i][0][strcspn(db[i][0], "\n")] = 0;
sfb;
printf("Ingrese legajo de %s: ", db[i][0]);
fgets(db[i][1], sizeof db[i][1], stdin);
db[i][1][strcspn(db[i][1], "\n")] = 0;
sfb;
printf("Ingrese edad de %s: ", db[i][0]);
fgets(db[i][2], sizeof db[i][2], stdin);
db[i][2][strcspn(db[i][2], "\n")] = 0;
sfb;
printf("Ingrese antiguedad de %s: ", db[i][0]);
fgets(db[i][3], sizeof db[i][3], stdin);
db[i][3][strcspn(db[i][3], "\n")] = 0;
sfb;
}
printt(&db);
}
void printt(char *dbp){
int i = 0;
for (int a = 0; a <= 20; a++){
printf("% 40c|% 20c|% 10c|% 15c\n", "Nombre", "Legajo", "Edad", "Antiguedad");
printf("% 40c|% 20c|% 10c|% 15c\n", *dbp[a][i], *dbp[a][i+1], *dbp[a][i+2], *dbp[a][i+3]);
i = i +4 ;
}
}
Here are all the errors I get when I try to compile (I hope that all of them are related to pointers):
passing argument 1 of 'printt' from incompatible pointer type [-Werror=incompatible-pointer-types] [35,12]
format '%c' expects argument of type 'int', but argument 2 has type 'char *' [-Werror=format=] [41,25]
format '%c' expects argument of type 'int', but argument 3 has type 'char *' [-Werror=format=] [41,32]
format '%c' expects argument of type 'int', but argument 4 has type 'char *' [-Werror=format=] [41,37]
format '%c' expects argument of type 'int', but argument 5 has type 'char *' [-Werror=format=] [41,43]
subscripted value is neither array nor pointer nor vector [42,56]
expression must have pointer-to-object type but it has type "int" [42,57]
subscripted value is neither array nor pointer nor vector [42,68]
expression must have pointer-to-object type but it has type "int" [42,69]
subscripted value is neither array nor pointer nor vector [42,82]
expression must have pointer-to-object type but it has type "int" [42,83]
subscripted value is neither array nor pointer nor vector [42,96]
expression must have pointer-to-object type but it has type "int" [42,97]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
