Created
April 4, 2015 15:28
-
-
Save eariassoto/044fb6772239143c76d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| void execute_command(char command, FILE *input){ | |
| char c; | |
| long pos; | |
| switch(command) { | |
| case '>': | |
| ++p; | |
| if(!*p) | |
| ++last_p; | |
| break; | |
| case '<': | |
| --p; | |
| break; | |
| case '+': | |
| ++*p; | |
| break; | |
| case '-': | |
| --*p; | |
| break; | |
| case '.': | |
| *curr_c = *p; | |
| ++curr_c; | |
| ++last_c; | |
| break; | |
| case ',': | |
| printf("Enter a character: "); | |
| *p = getchar(); | |
| break; | |
| case '[': | |
| if ((*p) == 0) { | |
| int loopc = 0; | |
| for(;;) | |
| { | |
| c = getc(input); | |
| if (loopc == 0 && c == ']') break; | |
| if (c == ']') loopc--; | |
| if (c == '[') loopc++; | |
| } | |
| }else{ | |
| break; | |
| } | |
| case ']': | |
| if((*p) != 0){ | |
| pos = ftell(input)-1; | |
| int loopc = 0; | |
| for(;;) | |
| { | |
| fseek(input, --pos, SEEK_SET); | |
| c = getc(input); | |
| if (loopc == 0 && c == '[') break; | |
| if (c == ']') loopc++; | |
| if (c == '[') loopc--; | |
| } | |
| }else{ | |
| break; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment