[[Code] /************************************************************************** * * Purpose: To filter some records. * Demonstrates the 'feof' & 'fgets' statemnts. * Author: M J Leslie * Date: 07-Jun-94 * *************************************************************************/ |
Input examples from stdin: |
[[Code] |
while (feof(stdin) == 0) |
while (feof(stdin) == 0) /* stdin is defined in stdio and is a FILE* datatype */ |
} } ] modified using poll() [[Code] #include <stdio.h> #include <stdlib.h> #include <sys/poll.h> #include <unistd.h> main() { struct pollfd fds; char data[80]; /* Record read from the file. */ int retval; int n; fds.fd = {STDIN FILENO}?; fds.events = POLLIN; fds.revents = 0; while ((retval=poll(&fds,1,5000))!=-1) // 5000 milliseconds { printf("retval: %d revents: %d\n",retval,fds.revents); if(fds.revents==1){ printf("reading data!\n"); n=read({STDIN FILENO}?, data, 100); /* Read next record */ data[n]=0; printf("%s",data); /* O/P the record to the screen */ } if (data[0] == '#') exit; /* filter out the comments */ |
|
modified using poll()
|