我不能使用atoi,需要按位數字做它..我如何將它保存在一個int ..給定一個字符*溫度把它放在一個int ..轉換字符數組爲一個int
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main() {
char* temp = "798654564654564654";
int i = 0;
for (i = 0; i < strlen(temp); i++) {
printf("%d", temp[i] - 48);
}
printf("\n");
}
你說你不能使用atoi,我假設這是作業? – Borgleader
從最左邊的數字開始,將它添加到一個臨時累加器,並且對於每個數字將累加器乘以十,並添加當前數字 –
,這將給出任意數字的整個int。int a = 798654564654564654; – user1762517