"stdin" is treated just like a file except you dont have to create a file decriptor, its already created. it has the type (FILE * stdin) #include <stdio.h> main() { int x; fscanf(stdin, "%d", &x); return (x << 4); } At 10:48 AM 3/14/01 -0600, you wrote: >So, how would I modify those two lines of code to allow me to do something >like: >echo 3 | ./bitshift > >I've never been able to figure out how to make a C program accept STDIN. Of >course, I haven't spent a whole lot of time looking either. > >Jay > >> -----Original Message----- >> From: Jason DeStefano [mailto:destef at destef.com] >> Sent: Tuesday, March 13, 2001 8:25 PM >> To: tclug-list at mn-linux.org >> Subject: Re: [TCLUG] bit shifting >> >> >> How about 2 lines? >> >> Reusable code...it makes C just as simple to crank out code as >> scripts. It also keeps a good programmer's skills sharp by always >> concentrating only on one language--and seperates the men from >> the boyz when it comes to writing quility code. But for the >> lighthearted >> I wouldn't recommend it because power=complexity. >> >> #include <stdlib.h> >> int main(int argc, char ** argv) { return (atoi(argv[1])<<4); >> } /* x*16 */ >> >> Now that wasnt so bad was it? >> >> cc -s -O3 bitshift.c >> >> exe size if 3.1K and is much more of an efficient OS call that running >> a perl script. But if you prefer scripting then fair enough since for >> software developers coding vs. scripting is somewhat of a holy >> war. >> >> I'd like to see perl compilers that can compete with C--then I'd >> be impressed. >> >> >> At 07:25 AM 3/12/01 -0600, you wrote: >> >Yes, but it's also like killing an ant with a hammer. A >> little overkill >> >when you're doing basic bit-shifting. >> > >> >Sure, C might be able to do a LOT more than C, but why do you want to >> >write 100 lines of code when you can do it in 4? >> > >> >Jason DeStefano wrote: >> >> >> >> heh. no, i mean C. it does a LOT more than perl--and a lot >> faster too. :) >> >> >> >> At 05:31 PM 3/11/01 -0600, you wrote: >> >> >On Sun, 11 Mar 2001, Jason DeStefano wrote: >> >> > >> >> >> Yeah, its called "C". >> >> > >> >> >You mean "Perl". >> >> > >> >> >2.5.9 Shift Operators >> >> > >> >> >The bit-shift operators (<< and >>) return the value of >> the left argument >> >> >shifted to the left (<<) or to the right (>>) by >> >> >the number of bits specified by the right argument. The >> arguments should >> >> >be integers. For example: >> >> > >> >> >1 << 4; # returns 16 >> >> >32 >> 4; # returns 2 >> >> > >> >> >Andy >> >> > >> >_______________________________________________ >> >tclug-list mailing list >> >tclug-list at mn-linux.org >> >https://mailman.mn-linux.org/mailman/listinfo/tclug-list >> > >> >> _______________________________________________ >> tclug-list mailing list >> tclug-list at mn-linux.org >> https://mailman.mn-linux.org/mailman/listinfo/tclug-list >> >_______________________________________________ >tclug-list mailing list >tclug-list at mn-linux.org >https://mailman.mn-linux.org/mailman/listinfo/tclug-list >