[問題] 如何解決副程式的值傳不回來問題

看板C_and_CPP (C/C++)作者 (aada)時間14年前 (2012/05/05 12:59), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串1/1
大家好, 請問一下關於副程式的問題, 我寫了一個取最大值的副程式但最後回傳不回來, 請大大幫我看一下問題在哪 謝謝 #include <stdio.h> #include <stdlib.h> #define NNx2 5 #define NNy2 5 // ___________ Max ___________ // void maxmax( double *I1, double temp2 ) { for ( int i = 0; i < NNx2*NNx2; i++ ) { if ( I1[i] > temp2 ) { temp2 = I1[i]; printf("maxmax temp =%f \n", temp2); } } } int main( void ) { char filename_I1[] = "a.txt"; double *I1,temp2 = 0; FILE *fp1; I1 = (double*) malloc( (NNx2)*(NNy2)*sizeof(double) ); fp1 = fopen( filename_I1, "r" ); for (int i = 0; i < NNx2*NNy2; i++) { fscanf( fp1,"%lf", &I1[ i ] ); } fclose( fp1 ); printf("\n"); maxmax( I1, temp2 ); printf("maxima=%f\n", temp2); system("pause"); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.112.230.1

05/05 13:02, , 1F
void maxmax( double *I1, double* temp2 )
05/05 13:02, 1F

05/05 13:03, , 2F
if ( I1[i] > *temp2 ){ *temp2 = I1[i];
05/05 13:03, 2F

05/05 13:03, , 3F
maxmax( I1, &temp2 );
05/05 13:03, 3F

05/05 13:09, , 4F
感謝s大的協助
05/05 13:09, 4F
文章代碼(AID): #1FfBEoyt (C_and_CPP)
文章代碼(AID): #1FfBEoyt (C_and_CPP)