Question by michaelR: How do you exit a loop by using the “enter” key in C?
I’ve noticed that “enter” key is ’13′ on the ASCII chart, however when i incorporate it into my code it does not work.
For example:
char = op;
scanf(“%s”, &op);
switch (op)
{
case 43:
printf(“It is a plus!\n”);
break;
case 45:
printf(“It is a subtraction!\n”);
break;
case :13
printf(“It is enter!\n”);
break;

43 and 45 work, but for 13 (the enter key) it doesn’t, how can I make it work by pressing the “enter” key?

Best answer:

Answer by BigRez
Try using 10 rather than 13.
Also use %c with the scanf rather than %s

You also have a few syntax errors in the code above.

What do you think? Answer below!