PDA

View Full Version : begining c



scorpious
July 23rd, 2012, 10:34 AM
why does the following programme make the value of "stop" 1 no matter what input I provide?

function() does not return anything.


#include <stdio.h>

int main() {
int stop = 0;
do {
function();
printf("type 1 to end");
stop = scanf("%d", &stop);
printf("%d", stop);
}while (stop != 1);

return 0;
}

Bachstelze
July 23rd, 2012, 10:50 AM
There are many things wrong with this code. For starters, check the man page for scanf(). Its return value is not what you think it is.

scorpious
July 23rd, 2012, 10:57 AM
Oh silly me. I put "stop =" unnecessarily.

You said there were many things wrong? what else did I do wrong? I seems to work fine now.

Bachstelze
July 23rd, 2012, 10:58 AM
What happens if you enter 'a'?

scorpious
July 23rd, 2012, 11:02 AM
hmmmm......