|
发表于 2003-9-9 14:22:25
|
显示全部楼层
Re: 求助高手
[code:1]#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int m, n, x;
if (argc < 4)
{
printf("error");
exit(1);
}
struct{
char operated[10];
char flag[2];
char operate[10];
} operation;
strcpy(operation.operated, argv[1]);
strcpy(operation.flag, argv[2]);
strcpy(operation.operate, argv[3]);
m = atoi(operation.operated);
n = atoi(operation.operate);
switch(operation.flag[0])
{
case '+':
x = m + n;
printf("%d + %d = %d", m, n, x);
break;
case '-':
x = m - n;
printf("%d - %d = %d", m, n, x);
break;
case '*':
x = m * n;
printf("%d * %d = %d", m, n, x);
break;
case '/':
x = m / n;
printf("%d / %d = %d", m, n, x);
break;
default:
break;
}
return 0;
}[/code:1]
一个小程序在RH8下编译通过,但也有两个问题,一是加减除都可用,但乘不可用,不知谁能告诉我为什么;二是,如果把m,n,x的类型改为long,printf()应该做怎样的修改? |
|