how do I find the length of input in C, when the input is via shell? -
let's say, user types in
echo abc, de | ./test
in shell (already have test.c compiled), how length of input (in case it's 7)?
count number of characters in standard input.
int main() { int n = 0; while (getchar() != eof) { n++; } n--; // ignore final newline printf("%d chars\n", n); return 0; }
Comments
Post a Comment