Created
February 23, 2020 23:00
-
-
Save barrucadu/252ebd8ae09f0f8f3c11182402747343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <setjmp.h> | |
#include <stdio.h> | |
int main(void) { | |
jmp_buf buf; | |
int a, b; | |
switch(setjmp(buf)) { | |
case 0: | |
case 1: | |
printf("Enter a number:\n"); | |
scanf("%d", &a); | |
printf("Enter a second number:\n"); | |
scanf("%d", &b); | |
longjmp(buf, (a == b) + 2); | |
case 2: | |
printf("%d != %d\n\nTry again, but enter two equal numbers this time!\n\n", a, b); | |
longjmp(buf, 1); | |
case 3: | |
printf("%d == %d\n", a, b); | |
break; | |
default: | |
fprintf(stderr, "???\n"); | |
return 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment