- 論壇徽章:
- 0
|
#include <stdio.h>
int main( void )
{
float score[4][5], *pscore = *score ;
int i,j;
for( i = 0 ; i < 4 ; i++ )
{
for( j = 0 ; j < 5 ; j ++ )
scanf("%f", pscore + 5 * i + j );
}
/*
其他代碼
*/
return 0;
}
這段代碼實際運行一定出現(xiàn)問題,運行結(jié)果為:
Debug Error!
Program: C:\test\Debug\test.exe
runtime error
只修改一點點即可:
#include <stdio.h>
int main( void )
{
float score[4][5] = {0}, *pscore = *score ;
int i,j;
for( i = 0 ; i < 4 ; i++ )
{
for( j = 0 ; j < 5 ; j ++ )
scanf("%f", pscore + 5 * i + j );
}
/*
其他代碼
*/
return 0;
}
有興趣可參見《scanf輸入浮點數(shù)時的問題》 http://kan.weibo.com/con/3521420118952837?_from=text
|
|