我傳遞一個參數傳遞給一個C程序:轉換陣列用C
程序名1234
int main (int argc, char *argv[]) {
int length_of_input = 0;
char* input = argv[1];
while(input[length_of_input]) {
//convert input from array of char to int
length_of_input++;
}
}
我希望能夠使用每個作爲整數分別傳遞給函數的參數的數字。 atoi(input [])會引發編譯時錯誤。
此代碼不能編譯:
while(input[length_of_input]) {
int temp = atoi(input[length_of_input]);
printf("char %i: %i\n", length_of_input, temp);
length_of_input++;
}
請更精確的你想要什麼。你期望一個包含{1,2,3,4}的int []嗎?此外,這聽起來像作業,所以標記爲 – 2011-04-26 21:51:50
肯定它是一個較大的家庭作業的一小部分,你可能已經看到我今天問過的其他問題。但我不認爲它需要被標記爲這樣,因爲這是一個微不足道的語言問題。 – 2011-04-26 21:56:01