Reserving seats in a movie theater I'm writing a C program to reserve seats in a movie theater. I am validating the selection of seats:

const int TOTAL_ROWS = 10;            // 1 to 26 -&gt; 'A' to 'Z'
const int SEATS_PER_ROW = 5;          // 1 to 9
int seats[TOTAL_ROWS][SEATS_PER_ROW]; // reserved seats, reserved seat == 1
char codes[TOTAL_SEATS][2];           // selected seats, e.g. A1, ..., Z9
...
for (i = 0; i &lt; required_seats; i++) {
    printf("Enter the code for the seat: %i: ", i + 1);
    scanf("%s", codes[i]);
    if (codes[i][0] &gt;= 'A' &amp;&amp; 
        codes[i][0] &lt;= 'A' + TOTAL_ROWS - 1 &amp;&amp; 
        codes[i][1] &gt;= '1' &amp;&amp; 
        codes[i][1] &lt;= '1' + SEATS_PER_ROW - 1) {

        if (seats[codes[i][0] - 'A'][codes[i][1] - '1'] == 1) {
            printf("Reserved seat. Select other.\n");
            i--;
        }
        for (j = 0; j &lt; i; j++) {
            if (codes[j][0] == codes[i][0] &amp;&amp; codes[j][1] == codes[i][1]) {
                printf("Repeated selection. Select other.\n");
                i--;
                break;
            }
        }
    } else {

        printf("Invalid code for seat.\n");
        i--;
    }
}


This code works fine. However, how can I refactor the code for this loop? In my opinion, using i-- does not look professional.



* By the way, you may want to see the full code &mdash;originally, in Spanish.
I/O

You want to read 2 characters although you use scanf("%s", codes[i]) this can have the effect you are overwriting the end of the buffer when you read scanf("%s", codes[required_seats-1]); since there is always an \0 added to your two characters. 

Either increase the buffer, change the format specifier or use an alternative method of reading from keyboard e.g. fgets() followed by sscanf() or simply read the characters one by one using fgetc(). The latter method has the advantage that you could prevent the user from entering invalid characters while he types.

You may also want to convert the characters to upper case just to be a bit more flexible towards the user (toupper())

structure

I think the code could do with some more functions to clarify the purpose. 

E.g. 

int isCodeValid(char* code)
{
  return code[0] &gt;= 'A' &amp;&amp; code[0] &lt;= 'A' + TOTAL_ROWS - 1 &amp;&amp; 
     code[1] &gt;= '1' &amp;&amp;  code[1] &lt;= '1' + SEATS_PER_ROW - 1;
}

int isRepeatedSelection(char* codes);
...


loop

What other suggested and as you mentioned already decrementing i in the for loop may be a bit confusing for the reader (well it was for me at least), having a do..while loop feels more natural here where the while condition is false until user enters correct code (or changes his mind and gives up).