如何從函數返回一個字符串的函數:如何編寫會返回一個字符串在C
char * temp;
int main()
{
temp = malloc(129);
double g_symbol_b_amount = 8536.700000;
printf("\n value: %s\t ", format_double_trans_amount(double g_symbol_b_amount));
}
char *format_double_trans_amount(double amount)
{
char amount_array_n1[25];
strcpy(amount_array_n, "");
sprintf(amount_array_n, "%1f", amount);
temp = amount_array_n;
return temp;
}
這裏我得到的值:0.000000
我需要的原單值,請幫我這個?
什麼是'amount_array_n'?這是爲你編譯的嗎?你能顯示生成的確切輸出嗎? – 2011-04-30 15:23:49
char amount_array_n1 [25]; – jcrshankar 2011-04-30 15:32:43
修復了格式。 – 2011-04-30 15:36:50