how do you make scanf read in numbers in a for loop?? this is what i want it to do:
example input:
45 34 67 78
scanf terminates after space is pressed so how do i get around that problem?
this is my code so far:
what should i put into the scan set for scanf to make it work? thanksCode:#include <stdio.h> void swap(int *p, int *q) { int tmp; tmp = *p; *p = *q; *q = tmp; } void bubble (int a[10]) { int i, j; for (i = 0; i < 9; i++) for (j = 9; i < j; j--) if (a[j - 1] > a[j]) swap(&a[j - 1], &a[j]); } int main (void) { int i; int a[10]; for (i = 0; i < 10; i++){ scanf ("%d\n", &a[i]);} bubble (a); for (i = 0; i < 8; i++) printf(" %d", a[i]); printf("\n"); printf("\n"); return 0; }



LinkBack URL
About LinkBacks


