私はまだポインタを学んでいないので、誰かが同じ質問をしているときに他の答えが何について話しているのかわかりません:S ...
while(1)
{
/* intializing variables for the while loop */
temp1 = 0;
temp2 = 0;
val = 0;
for(counter = 0; counter < 256; counter++)
{
input[counter] = ' ';
}
scanf("%s", &input); /* gets user input */
if(input[0] == 'p') /* if user inputs p; program pops the first top element of stack and terminates the loop */
{ /* and the program overall */
printf("%d", pop(stack));
break;
}
if(input[0] == '+' || input[0] == '-' || input[0] == '*') /* if operator is inputted; it pops 2 values and does the arithemetic process */
{
if(stackCounter == 1 || stackCounter == 0) /* If user tries to process operator when there are no elements in stack, gives error and terminates */
{
printf("%s", "Error! : Not enough elements in stack!");
break;
}
else
{
temp1 = pop(stack);
temp2 = pop(stack);
push(stack, arithmetic(temp2, temp1, input[0]));
}
}
else /* if none of the above, it stores the input value into the stack*/
{
val = atoi(input); /* atoi is used to change string to integer */
push(stack, val);
}
}
これは、有限スタックで接尾辞と同じ操作を実行するためのプログラムです。他の機能はすべて正常に機能しています。Visual Studioでコンパイルして実行すると正常に動作しますが、Linux(プログラムのテストに使用)で実行すると動作しません。「c:52:警告:char形式、異なるタイプのarg(arg 2)」と表示されます。
問題を引き起こしているのはscanfまたはatoi関数だと思います...
数文字変更するだけでこのプログラムを簡単に修正する方法はありますか?