最初由 VicLin 發表
#include <stdio.h>
#include <conio.h>
main(){
float A;
float B;
scanf("%f",&A);
A *= 1.5;
printf("轉換後的溫度 : %f",A);
getch(); <--- 多餘的程式碼..
}
這樣就成了
這種算比較簡單的題目
嗯..
這樣寫是比較簡單沒錯, 不過這樣一開始就造成了 Security Issue 了..
語法:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#define STRING_SIZE 16
int main( int argc, char *argv[] ) <--- ANSI C 定義的 main function
{
int res;
double value;
char str[STRING_SIZE];
res = fgets( str, STRING_SIZE - 1, stdin );
/* Error Checking */
if ( EOF == res )
{
fprintf( stderr, "Error in receving float data from console\n" );
_exit( 1 );
}
/* Successfully, convert INPUT to float value */
value = atof( str ) * 1.5;
printf( "轉換後的溫度 : %f", value );
return 0; <--- 0 代表成功, 其他代表不同的意義( > 0 )
}
書籤