我再次参与这个项目。我在阅读输入文本时遇到问题导致程序永远不会结束。这里的问题full description of the problem 但我不知道如何通过char读取文本char,然后以相同的方式读取下一行。
freopen("input.txt","rt",stdin);
freopen("output.txt","wt",stdout);
int n=-1;
int m=-1;
int cont =0;
int VMatriz[100][100]={0};
int Mapa[100][100]={0};
while(n!=0 && m!=0)
{
scanf("%d %d",&n,&m);
if (n==0 && m==0)
break;
cont++;
printf("Field # %d",cont);
for (int i=0;i<n;i++)
{ printf("/n");
for (int j=0;j<m;j++)
{
//scanf("%d ",&Mapa[i][j]);
Mapa[i][j]=getchar();
if (Mapa[i][j]=='*')
{
if (j-1>=0)
VMatriz[i][j-1]++;
if (j+1<m)
VMatriz[i][j+1]++;
if (i-1>=0)
VMatriz[i-1][j]++;
if (i+1<m)
VMatriz[i+1][j]++;
if (j-1>=0 && i-1>0)
VMatriz[i-1][j-1]++;
if (j-1>=0 && i+1<m)
VMatriz[i+1][j-1]++;
if (j+1<m && i-1>0)
VMatriz[i-1][j+1]++;
if (j+1<m && i+1<m)
VMatriz[i+1][j+1]++;
VMatriz[i][j]='*';
printf("%d",VMatriz[i][j]);
}
}
}
printf("/n");
}
return 0;
答案 0 :(得分:0)
首先使逻辑简单
您可以使用CStdioFile
CStdioFile file (_T("File.txt"), CStdioFile::modeRead);
CString buffer;
while (file.ReadString(buffer))
{
CString strLine = buffer;
//Parse the strLine for each character
}