1

I want when I reserve or cancel, the number change, but it doesn't change. Im confused.. please help :!!

print seat code :

  int print_seats(void) {
        int i, j;

        printf("  |0  1  2  3  4\n");
        printf("  ---------------\n");

        for (i = 0; i < 3; i++)
        {
            printf("%d|", i);
            for (j = 0; j < 5; j++)
            {

it doesnt print 0:

            printf("%2d ", s[i][j]);
        }
        printf("\n");   
    }
    printf("\n");
}

reserve code :

int researve(int s[3][5]) {
    int row = 0, col = 0;

    printf("선택된 메뉴=예약하기\n\n");
    printf("예약을 원하는 자리는?(행 열) :");
    scanf("%d %d", &row, &col);

succed :

if (s[row][col] == 0)
        {           
            printf("예약이 완료되었습니다\n\n");
            s[row][col] = 1;
        }

fail : else { printf("예약이 완료되었습니다\n\n"); } return s[3][5]; }

main code :

int main(void) {
    int s[3][5] = {{ 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }
    };

selecting menu :

            printf("선택된 메뉴=좌석 확인하기\n\n");
            print_seats();
            researve(s[3][5]);
            print_seats();

    return 0;
}
2
  • There's another code here: Where? Commented May 19, 2020 at 14:02
  • 3
    Note that return s[3][5]; at the end of function int researve(int s[3][5]) will access an out of range (non-existent) array element. Commented May 19, 2020 at 14:04

1 Answer 1

1

I think you just want to remove this line:

s[i][j]=0; 

in print_seats. At the beginning of your program, it's already 0.

A function that prints an argument should usually not change it.

You are already updating this to 1 in reserve, but you revert that change every time you print.

Also, as @WeatherVane mentioned in a comment, the return s[3][5] is never a valid int. You probably should make this void and not return anything, but returning s[row][col] would be ok.

I should also mention that you should check that row/col are within range of your array before using them as indexes.

Sign up to request clarification or add additional context in comments.

3 Comments

if i remove that line its execute a weird number
You should pass s from main to the function
It looks like you might have another (global) s. The one in main is initialized to 0. But it looks like you aren’t using it in print_seats

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.