【发布时间】:2011-05-04 02:34:34
【问题描述】:
假设我有:
Operand[2][4] = {{"1", "2", "3", "4"},{"5", "6", "7", "8"}};
我有一些名为 Operand1_sign 和 Operand2_sign 的位变量(0:正数和 1:负数)假设它们是:
Operand1_sign = 0;
Operand2_sign = 1;
如何将其转换为 2 个整数并对它们进行一些运算(例如求和)
即
signed int Operand1, Operand2, Result;
所以最后我可以得到以下内容:
Operand1 = + 1234;
Operand2 = - 5678;
Result = Operand1 + Operand2;
【问题讨论】:
-
int atoi (const char * str) ?,见cplusplus.com/reference/clibrary/cstdlib/atoi
-
我没有注意到您添加了“作业”标签。我错过了什么吗?
-
这只是PIC18项目的一小部分
-
@Tong: 如何输入 Operand[][] 作为 atoi() 的参数?抱歉,我习惯了 JAVA,我是 C 的新手 :)
-
顺便说一句,
atoi将失败,因为Operand值不是以 0 结尾的。如果你有char Operand[2][5] = {{'1', '2', '3', '4', '\0'},{'5', '6', '7', '8', '\0'}};,它会起作用