I am passing a number int into this method but it is not storing the int in the method that calls the intchange method. Any pointers?
int intchange(const char *prompt, int number){
char buffer[LINESIZE];
while(1){
printf("%s", prompt);
if(!fgets(buffer,LINESIZE, stdin)){
clearerr(stdin);
return 0;
}
if(sscanf(buffer, "%d", &number) == 1){
/*exit variable */
if(number== -1)
return 0;
else if (number<= 110 && number>= 0)
return 1;
}
}
}
Thanks!
In order for the change to be visible to the caller you need to pass the address of the
intintointchange(). Otherwise a copy of theintprovided by the caller is being changed, not theintthe caller provided as C passes by value:Invoked:
See Does C even have “pass by reference”?.