我试图在 switch 语句中实现移位运算符,但我无法获得输出。我试图做一个简单的左移,比如 '12 << 2' 应该返回 '12 << 2: 48' 这是我的代码:
#include <stdio.h>
void shift(){
char op = 0;
int x = 0;
int y = 0;
char buffer[1024];
int iCont = -1;
char c1 = 0;
char c2 = 0;
do
{
printf("\ninput: ");
fgets(buffer, sizeof(buffer), stdin);
if (sscanf(buffer, "%d %c%c %d", &x, &c1, &c2, &y)){}
switch (op)
{
case '<<': printf("%d %c1%c %d = %d", x, c1, c2, y, x << y);
break;
case '>>': printf("%d %c1%c %d = %d", x, c1, c2, y, x >> y);
default:
break;
}
} while (iCont);
}