3
How do I do? I’m trying to:
#include <stdio.h>
#include <stdlib.h>
int changeMap(char mp[], int x, int y){
mp[x-1][y-1] = 'X';
return 0;
}
int main(){
char map[][1] = "gabriel";
printf("%c", map[0][0]);
changeMap(map, 1, 1);
printf("%c", map[0][0]);
return 0;
}
The wish is that you return:
t
X
But returns:
G:\PROJETOS\C\main.c||In function 'changeMap':|
G:\PROJETOS\C\main.c|4|error: subscripted value is neither array nor pointer nor vector|
G:\PROJETOS\C\main.c||In function 'main':|
G:\PROJETOS\C\main.c|8|error: invalid initializer|
G:\PROJETOS\C\main.c|10|warning: passing argument 1 of 'changeMap' from incompatible pointer type [enabled by default]|
G:\PROJETOS\C\main.c|3|note: expected 'char *' but argument is of type 'char (*)[1]'|
||=== Build failed: 2 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
I thought to modify directly map would have to create a pointer to char, but so it worked.
– axell-brendow
Also has something else, its function returna 0 that is thrown away, it better be
void
nay ?– axell-brendow
It depends on @axell13... I just kept the AP code.
– Jorge B.
Got it. Great answer.
– Gabriel Sales