![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how do collect shell output in a C program | damn_bkb | UNIX for Advanced & Expert Users | 5 | 05-25-2009 11:23 PM |
| C program Output | arunviswanath | High Level Programming | 3 | 07-05-2007 02:16 AM |
| how can I use the stream output in other program | umen | UNIX for Dummies Questions & Answers | 1 | 02-02-2006 07:55 AM |
| Capturing output from C++ program | GMMike | UNIX for Dummies Questions & Answers | 3 | 03-08-2005 09:04 AM |
| Capturing cli Program output | Christopher | High Level Programming | 1 | 12-06-2001 11:08 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
ambiguity in program output
1 #include <fcntl.h>
2 3 main(int argc, char *argv[]) 4 { 5 char buf[1]; 6 int fd, count = 0; 7 8 if (argc > 1) 9 fd = open(argv[1], O_RDONLY); 10 else 11 fd = 0; /* Use standard input */ 12 13 while (read(fd, buf, 1) > 0) { 14 if (count < 5) write(1, buf, 1); 15 if (buf[0] == '\n') count++; 16 } 17 } Here buf can store only one character. But if i run it as:- "prog_name /etc/passwd" how does it give first five lines. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|