1
두 숫자의 곱셈을 수행하고 있습니다. * 연산자는 유효한 ASCII 값으로 간주되지 않습니다."*"에 대한 가비지 값 가져 오기 ASCII
main.c를
int mul (int x, int y)
{
int ans;
ans = x * y;
return (ans);
}
샘플 출력
#include <stdio.h>
extern int add();
extern int mul();
main(int argc, char *argv[])
{
char oper;
oper = (char)argv[2][0];
printf("\n argv: %d : %d : %d\n",atoi(argv[1]),atoi(argv[2]),atoi(argv[3]));
if (oper == '+')
printf ("%d\n", add(atoi(argv[1]), atoi(argv[3])));
if (oper == '*')
printf ("%d\n", mul(atoi(argv[1]), atoi(argv[3])));
}
mul.c :
[email protected]:~/a/make$ ./basic 1 + 2
argv: 1 : 0 : 2
3 //=> gives the correct answer after addition
[email protected]:~/a/make$ ./basic 1 * 2
argv: 1 : 0 : 0
//Doesnt output any the answer.
왜 정크 값을 받고 인수 및 곱셈은 왜하지입니다.
은 무엇을 기다리고처럼, 문자
*
및?
을 탈출해야한다는하지 않으려면? .... 정말? –Windows에서'echo *'가 달라지기를 원합니다. –
Windows에서 반드시 그런 것은 아니지만 Unix-ish 쉘 (여기서 사용되는 쉘과 동일)에 대해서는 사실입니다. –