c - do..while loop - not breaking when condition met -
so these few lines of code want keep storing inputs array until dot('.') written. when dot written nothing happens, makes me put input.
#include <stdio.h> #include <stdlib.h> #define max 100 int main() { char array[max]; int = 0; do{ scanf("%c", &array[i]); i++; }while(array[i] != '.'); return 0; }
in do..while loop, block executed before while condition evaluated. that's whole point.
you filling array[i] scanned character, incrementing i evaluate array[i+1] if input, @ array[i].
you want swap out normal loop.
when debugging sort of thing, want start double checking if condition think being met being met, example debug printing condition value. printing array[i] @ last line of block.
Comments
Post a Comment