看板 C_and_CPP 關於我們 聯絡資訊
大家好, 請問一下關於副程式的問題, 我寫了一個取最大值的副程式但最後回傳不回來, 請大大幫我看一下問題在哪 謝謝 #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
stupid0319:void maxmax( double *I1, double* temp2 ) 05/05 13:02
stupid0319:if ( I1[i] > *temp2 ){ *temp2 = I1[i]; 05/05 13:03
stupid0319:maxmax( I1, &temp2 ); 05/05 13:03
aada:感謝s大的協助 05/05 13:09