私が作成しているこのCプログラムは、コマンドラインから一連の文字を読み取り、配列(argv [])を使用してそれらを保存します
main (int argc, char *argv[]) {
int temp;
/*prevents no arguments*/
if (argc==1){
printf("Usage;\t[0 < integers < 9] [operators]\n");
exit(0);
}
int i;
for (i = 0 ; i<argc; i++){
temp = argv[i] - '0';
printf("this is char %d ; %d\n",i, temp);
}
}
しかし、そのようにコマンドラインで実行した後に得られるのはすべてです。
program 2 4 1 - +
ランダムゴミです
this is char 0 ; -4195956
this is char 1 ; -4195950
this is char 2 ; -4195948
this is char 3 ; -4195946
this is char 4 ; -4195944
this is char 5 ; -4195942
temp をキャストする方法に何か問題がありますか? それとも、(*argv[] 内の) ポインターの概念が間違っているのでしょうか?