Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
void move(){
int i;
int j;
char choice;
scanf("%s",&choice);
for (i = 0; i < rows; ++i) {
for (j = 0; j < cols; ++j) {
if(maze[i][j] == 'p' && choice == 'a'){
char tmp = maze[i][j];
maze[i][j] = maze[i][j-1];
maze[i][j-1] = tmp;
}
if(maze[i][j] == 'p' && choice == 'w'){
char tmp = maze[i][j];
maze[i][j] = maze[i-1][j];
maze[i-1][j] = tmp;
}
if(maze[i][j] == 'p' && choice == 'd'){
char tmp = maze[i][j];
maze[i][j] = maze[i][j+1];
maze[i][j+1] = tmp;
}
if(maze[i][j] == 'p' && choice == 's'){
char tmp = maze[i][j];
maze[i][j] = maze[i+1][j];
maze[i+1][j] = tmp;
}
}
}
}
Indentation style - Wikipedia[
^]
Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[
^]
ultraedit[
^]
-----
Your code is very simple minded, this leads to repeating mostly same code.
First thing you repeat same thing everywhere in the loop:
void move(){
int i;
int j;
char choice;
scanf("%s",&choice);
for (i = 0; i < rows; ++i) {
for (j = 0; j < cols; ++j) {
if(maze[i][j] == 'p'){
if(choice == 'a'){
char tmp = maze[i][j];
maze[i][j] = maze[i][j-1];
maze[i][j-1] = tmp;
}
if(choice == 'w'){
char tmp = maze[i][j];
maze[i][j] = maze[i-1][j];
maze[i-1][j] = tmp;
}
if(choice == 'd'){
char tmp = maze[i][j];
maze[i][j] = maze[i][j+1];
maze[i][j+1] = tmp;
}
if(choice == 's'){
char tmp = maze[i][j];
maze[i][j] = maze[i+1][j];
maze[i+1][j] = tmp;
}
}
}
}
}
This code is faster because it test for 'P' once per loop instead of 4 times.
other optimizations are possible.
-----
My guess is that 'p' is the player.
Problem, your code do not check for walls.
Problem, your code do not check if player will stay in maze.
Problem, when moving down or right, p is moved to a new position that will be visited by loops and thus moved again, until moved after the end of maze.
Advice keep track of position of p with 2 variables px and py, it avoid the need of 2 loops when moving p.