how would i read inputs into an array until the number 0 is imputed, which at that point continues to a sorting function. I have a sorting function written, i just don't know how to terminate the inputing.
how would i read inputs into an array until the number 0 is imputed, which at that point continues to a sorting function. I have a sorting function written, i just don't know how to terminate the inputing.
read a number
if it's zero stop
process
go back to top of loop
How are you getting input?
If you are using getchar() in a while loop then you can use break to get out of the while loop if getchar() returns a 0.
Code:while { /* stuff */ if( something == 0 ) break; /* exits the while loop */ }
getchar() would return the ascii value of 0 if the user inputs 0. So the checking condition would be getchar()=='0'. Why would you want to use getchar() anyway? A simple scanf() would do.If you are using getchar() in a while loop then you can use break to get out of the while loop if getchar() returns a 0.
Code:do { scanf("%d",&n); if(n==0)break; do stuff; }while(1); sort the array;
Code:>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.