still getting w a...what can i do further?where's the mistake? is that in output format?
[code][/code]
#include <stdio.h>
#include <stdlib.h>
int pos(int x,int y,char **ch,int r,int c)
{
if(x>=0 && y>=0 && x<r && y<c)
{
if(ch[x][y]=='*')
return 1;
}
return 0;
}
int main ()
{
int r,c,k;
char **ch;
for(k=1;;k++)
{
scanf("%d %d",&r,&c);
if(r==0&&c==0)
{
break;
}
int i,j,count;
ch=(char **)malloc(r*sizeof(char*));
for(i=0;i<r;i++)
{
ch[i]=(char *)malloc(c+1);
}
for(i=0;i<r;i++)
{
scanf("%s",ch[i]);
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
count=0;
if(ch[i][j]=='.')
{
if(pos(i+1,j,ch,r,c))
{
count++;
}
if(pos(i,j+1,ch,r,c))
{
count++;
}
if(pos(i+1,j+1,ch,r,c))
{
count++;
}
if(pos(i+1,j-1,ch,r,c))
{
count++;
}
if(pos(i-1,j+1,ch,r,c))
{
count++;
}
if(pos(i-1,j,ch,r,c))
{
count++;
}
if(pos(i,j-1,ch,r,c))
{
count++;
}
if(pos(i-1,j-1,ch,r,c))
{
count++;
}
ch[i][j]=count+'0';
}
}
}
printf("\nField #%d:\n",k);
for(i=0;i<r;i++)
{
printf("%s\n",ch[i]);
}
for(i=0;i<r;i++)
{
free(ch[i]);
}
free(ch);
}
return 0;
}
