Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // inspired by this StackOverflow page:
- // https://stackoverflow.com/questions/8202199/is-it-possible-to-use-goto-with-switch
- // tested in C17 (gcc)
- #include <stdio.h>
- int excuseMeWhatTheHeck(int,int);
- // takes 2 digits as commandline parameters: ./<file> <option> <condition>
- // condition is used as boolean
- int main(int argc, char const *argv[])
- {
- if (argc < 3) {
- printf("Not enough arguments (%d), expected 2\n (additional arguments will be discarded)\n", argc - 1);
- return 1;
- }
- int option = *argv[1] - 48;
- int condition = *argv[2] - 48;
- printf("option: %d condition: %s return: %d\n", option, condition ? "true" : "false", excuseMeWhatTheHeck(option, condition));
- }
- int excuseMeWhatTheHeck(int option, int condition) {
- switch(option) {
- case 0:
- if(condition)
- case 1:
- case 2:
- return 1;
- else
- case 3:
- default:
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment