Skip to content

Instantly share code, notes, and snippets.

@barrucadu
Created February 23, 2020 23:00
Show Gist options
  • Save barrucadu/252ebd8ae09f0f8f3c11182402747343 to your computer and use it in GitHub Desktop.
Save barrucadu/252ebd8ae09f0f8f3c11182402747343 to your computer and use it in GitHub Desktop.
#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