求大神二位字符数组函数出错
#include <stdio.h>#include <string.h>
void press_a(char *s[5],int line,int row)
{
char ch;
if(row!=1)
{
ch=*(s[line-1]+row-1);
*(s[line-1]+row-1)=*(s[line-1]+row-2);
*(s[line-1]+row-2)=ch;
}
row--;
}
void press_w(char *s[5],int line,int row)
{
char ch;
if(line!=1)
{
ch=*(s[line-1]+row-1);
*(s[line-1]+row-1)=*(s[line-2]+row-1);
*(s[line-2]+row-1)=ch;
}
line++;
}
void press_s(char *s[5],int line,int row)
{
char ch;
if(line!=5)
{
ch=*(s[line-1]+row-1);
*(s[line-1]+row-1)=*(s[line]+row-1);
*(s[line]+row-1)=ch;
}
line--;
}
void press_d(char *s[5],int line,int row)
{
char ch;
if(row!=5)
{
ch=*(s[line-1]+row-1);
*(s[line-1]+row-1)=*(s[line-1]+row);
*(s[line-1]+row)=ch;
}
row++;
}
int main()
{
char *s[5]={"TRGSJ","XDOKI","M VLN","WPABE","UQHCF"};
int n;
static int line=3, row=2;
int i,j;
while(1)
{
scanf("%d",&n);
switch(n)
{
case 1:
press_a(s,line,row);
break;
case 5:
press_w(s,line,row);
break;
case 2:
press_s(s,line,row);
break;
case 3:
press_d(s,line,row);
break;
default:
break;
}
for(i=0;i<5;i++)
{
printf("%s",s[i]);
printf("\n");
}
}
return 0;
}