Tuesday, 17 September 2013

how to store input from echo in arrays on C

how to store input from echo in arrays on C

if I were to type in echo "1001" | ./test in the terminal.
and test takes "1001" and stores it into a array how would I do that
in test.c
#include <stdio.h>
main() {
int c, i, j;
int a[4];
while(c = (getchar() != EOF)) {
a[i++] = c;
}
for(j = 0; j < 5; j++ {
printf("%d", a[j]);
}
}
but it's not working.

No comments:

Post a Comment