Markus Rechberger / Input
 
StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern

Veränderung (letzte Änderung) (Autor, Normalansicht)

Verändert: 1,9c1
[[Code]
/**************************************************************************
*
* Purpose: To filter some records.
* Demonstrates the 'feof' & 'fgets' statemnts.
* Author: M J Leslie
* Date: 07-Jun-94
*
*************************************************************************/
Input examples from stdin:

Hinzugefügt: 10a3
[[Code]

Verändert: 16c9
while (feof(stdin) == 0)
while (feof(stdin) == 0) /* stdin is defined in stdio and is a FILE* datatype */

Hinzugefügt: 20a14,44
}
}
]

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 */

Input examples from stdin:

#include <stdio.h>

main()
{
  char data[80];                /* Record read from the file.           */
  while (feof(stdin) == 0)      /* stdin is defined in stdio and is a FILE* datatype */
  {
    fgets(data, 2, stdin);      /* Read next record                     */
    if (data[0] == '#') exit; /* filter out the comments                */
    printf("%s",data);  /* O/P the record to the screen         */
  }
}

modified using poll()

#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                */
  }
}


StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern
Text dieser Seite ändern (zuletzt geändert: 20. Januar 2005 7:46 (diff))
Suchbegriff: gesucht wird
im Titel
im Text