Now, the problem I get is when a user exits, leaving me with a partially-filled array. Let's say they enter values for 0-8, so 9-19 are left blank, when I run the loop it prints random values for 9-19.Code:#include <stdio.h> void display_array(int array[], int c); int main(void) { int c, k, array[20]; for(c = 0, k = 0; c < 20; c++) { printf("Enter a whole number, to end enter: -1. "); scanf("%d", &k); if(k == -1) break; array[c] = k; } display_array(array, c); getch(); } void display_array(int array[], int c) { for(c = 0; c < 20; c++) { if(array[c] == ) break; printf("%d\n", array[c]); } }
Is there a way to write an if statement to check for whether or not a value has been entered?
Thanks in advance,
~Alan



LinkBack URL
About LinkBacks



