我希望使用串連作爲數學運算符,關鍵字就是這樣ç串聯操作VS +運營商
#include <stdio.h>
void main() {
int a = 15;
int b = 15;
char var = '+';
printf("result: %d", (a, var, b));
return 0;
}
我希望使用串連作爲數學運算符,關鍵字就是這樣ç串聯操作VS +運營商
#include <stdio.h>
void main() {
int a = 15;
int b = 15;
char var = '+';
printf("result: %d", (a, var, b));
return 0;
}
你可以爲每個操作員做
#include <stdio.h>
void main(char **argv, int argc) {
int a = 15;
int b = 15;
char var = '+';
if (var == '+') { // Check to see if it is a '+' and then add if so
printf("result: %d\n", a + b); // the \n prints a newline
}
return 0;
}
。你可以考慮使用類似flex
的東西來解析令牌。
爲什麼downvotes這個答案?爲什麼在這個問題上?我們不是都曾經來過這裏嗎? – Parentheses
Milliennium Bug看,問題是我想得到兩個數字和操作想要的(如字符'+'或' - '..等等),那麼我需要做的calcul沒有使用條件在操作 –
就像那樣: #include
如何充分利用殼一些幫助:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char buf[80];
int a = 15;
int b = 15;
char var = '+';
snprintf(buf, sizeof buf, "echo $[%d%c%d]", a, var, b);
return system(buf);
}
它適用於Unix和OS/X。我不知道Windows,但我聽說他們現在出貨。支持許多運營商:+
,-
,*
,/
,%
,^
,|
,&
也,
,<
和>
。
而我想要一千萬美元。或二十.. –
這不是C的工作原理。包含運算符的字符串不像運算符。 – Barmar