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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -