Update (int) variable in C inside a function [duplicate]

stage is passed by value to changeStage. stage = 1 only changes the local value of stage in changeStage, not the value of stage in main. You have to pass a pointer instead:

while (stage != 0) {
    changeStage(&stage);
}

void changeStage(int *stage) {
    *stage = 1;
}

Leave a Comment