I need some kind of brilliant insight into the code at the following URL
http://www.daniweb.com/code/snippet266.html
The question stems from mygeti() in the following code.
Isn't the lineCode:#include <stdio.h> int mygeti(int *result) { char buff [ 13 ]; /* signed 32-bit value, extra room for '\n' and '\0' */ return fgets(buff, sizeof buff, stdin) && sscanf(buff, "%d", result) == 1; } int main(void) { int value; do { fputs("Enter an integer: ", stdout); fflush(stdout); } while ( !mygeti(&value) ); printf("value = %d\n", value); return 0; }
A bit non-portable? What happens if the code was compiled under a 16 bit machine? Or more to the point, any type of machine who's int type is not 32 bit. Wouldn't the code break?Code:char buff [ 13 ];



LinkBack URL
About LinkBacks


