Código
#include <stdio.h> #define TRUE 1 #define FALSE 0 #define MAX 100 /* the maximum number of commands */ /* function prototypes */ void getCommands( int commands[][ 2 ] ); int turnRight( int d ); int turnLeft( int d ); void movePen( int down, int a[][ 50 ], int dir, int dist ); void printArray( int a[][ 50 ] ); int main(int argc, const char * argv[]) { //Declaraciones int penDown = FALSE; int command; int direction = 0; int commandArray[MAX][ 2 ] = {0}; int distance; int count = 0; //Fin Declaraciones getCommands( commandArray ); command = commandArray[ count ][ 0 ]; while(command!=9){ switch (command) { case 2: penDown = TRUE; break; /* exit switch */ case 3: direction = turnRight( direction ); break; /* exit switch */ case 4: direction = turnLeft( direction ); break; /* exit switch */ case 5: distance = commandArray[count][1]; break; /* exit switch */ case 6: break; /* exit switch */ } /* end switch */ command = commandArray[ ++count ][ 0 ]; } /* end while */ return 0; }/**************-FIN-DE-MAIN-***************/ void getCommands( int commands[][2]) { int i; /* counter */ int tempCommand; /* temporary command holder */ /* recieve commands until -9 or 100 commands perform action */ for(i=0;tempCommand!=9&&i<MAX;i++){ commands[ i ][ 0 ] = tempCommand; /* ignore comma after 5 is entered */ if ( tempCommand == 5 ) { } /* end if */ } commands[ i ][ 0 ] = 9; }/* FIN DE GET COMMANDS */ int turnRight( int d ) { return ++d > 3 ? 0 : d; } int turnLeft( int d ) { return --d < 0 ? 3 : d; } void movePen( int down, int a[][ 50 ], int dir, int dist ) { int i; int j; static int xPos = 0; static int yPos = 0; /* determine which way to move pen */ switch(dir){ case 0: for (j=1;j<=dist&&yPos+j<50;j++){ if (down) { a[xPos][yPos+j]=1; } /* end if */ } yPos += j - 1; break; /* exit switch */ case 1: /* move down */ /* move dist spaces or until edge of floor */ for (i=1;i<=dist&&xPos+i<50;i++){ if (down) { a[xPos+i][yPos] =1; } } xPos += i - 1; break; case 2: /* move to the left */ for (j=1;j<=dist&&yPos-j>=0;j++){ if (down){ a[xPos][yPos-j]=1; } /* end if */ } yPos -= j - 1; break; /* exit switch */ case 3: /* move up */ /* move dist spaces or until edge of floor */ for (i=1;i<=dist&&xPos-i>=0;i++){ if (down){ a[xPos-i][yPos]=1; } /* end if */ } xPos -= i - 1; break; /* exit switch */ } } void printArray( int a[][ 50 ] ) { int i; /* counter */ int j; /* counter */ /* loop through array */ for ( i = 0; i < 50; i++ ) { /* loop through array */ for ( j = 0; j < 50; j++ ) { } /* end for */ } /* end for */ }
El código está simplemente copiado y como dije anteriormente me gustaría saber como es que esto..
Código
ignora la coma pues lee la variable tempCommand pero ésta fue previamente escaneada y ahí luego luego viene mi problema al meter el 5 y la coma, si alguien me pudiera ayudar se lo agradecería para avanzar en mi aprendizaje.
if ( tempCommand == 5 ) { } /* end if */