I'm writing a function that will be called everytime the program ask for the user to input something.
My problem is,it's not printing the number entered,but the memory location(i think).And also,when a invalid(over-length) input,it still print out the memory location.Code:int main(voidz) { char integer[INT_SIZE+EXTRA_SPACES]; int number; printf("Enter a number."); *integer=getInput(INT_SIZE); number=atoi(integer); printf("%i",&integer); } void readRestOfLine() { int c; /* Read until the end of the line or end-of-file. */ while ((c = fgetc(stdin)) != '\n' && c != EOF); /* Clear the error and end-of-file flags. */ clearerr(stdin); } char* getInput(int size) { char input[size+EXTRA_SPACES]; fgets(input,size+EXTRA_SPACES,stdin); if (input[strlen(input) - 1] != '\n') { /* String was too long. Reject string and flush input buffer. */ printf("Input was too long.\n"); readRestOfLine(); } else { input[strlen(input) - 1] = '\0'; return input; } }
Thanks.