-4
我昨天開始學習C語言,並做了一個簡單的二進制轉換器。它可以在我的PC上正常工作,但是,除了could9以外,它不適用於大多數在線代碼運行程序(編譯器)。它看起來像scanf函數一般與在線IDE不兼容?scanf對在線跑步者不起作用
這是代碼。
#include <stdio.h>
#include <string.h>
int main(){
int a;
int b;
int c[255];
char opt[100];
printf("10進數の値を入力してください > ");
scanf("%d", &a);
printf("計算式を表示しますか? y(yes) or n(no) > ");
scanf("%s", opt);
if(strcmp(opt, "y") == 0){
printf("\n計算式: \n");
}
int i = 0;
while(a > 0){
b = a/2;
c[i] = a % 2;
if(strcmp(opt, "y") == 0){
printf("%d ÷ 2 = %d 餘り %d\n", a, b, c[i]);
}
a = b;
i++;
}
printf("\n2進數: ");
int j;
for(j = i-1; j >= 0; j--){
printf("%d", c[j]);
}
printf("\n");
return 0;
}
任何意見將不勝感激。
你得到了什麼錯誤? – CinCout
你沒有設置輸入? [ideone上的DEMO](http://ideone.com/LZcUMF) – BLUEPIXY