Skip to content

Instantly share code, notes, and snippets.

@eariassoto
Created April 4, 2015 15:28
Show Gist options
  • Select an option

  • Save eariassoto/044fb6772239143c76d5 to your computer and use it in GitHub Desktop.

Select an option

Save eariassoto/044fb6772239143c76d5 to your computer and use it in GitHub Desktop.
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