Solved

Detecting ctrl-d while reading stdin

Posted on 1998-02-26
3
530 Views
Last Modified: 2013-12-26
I am trying to write a utility that will get a line of input from stdin, and when the return key is pressed, do some processing on what was enterd.  Then, get another line and so on until cntl-d is pressed by the user.

How would I implement something like this in c??
0
Comment
Question by:corvin
  • 2
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1296071
#include <stdio.h>
main(){
  char line[1000];
  /*system("stty eof \004");*/
  while( !feof(stdin) ){
    if( fgets(line,999,stdin) ){ printf("process:%s",line); }
  }
}

0
 
LVL 1

Accepted Solution

by:
Rajkumar_R earned 50 total points
ID: 1296072
The code given by ozo will work but you cannot over come some intrupts like cntrl+c , cntrl+z which are abort signals send to the process.  
0
 
LVL 84

Expert Comment

by:ozo
ID: 1296073
If you want code to overcome ctrl-c, ctrl-z, just ask.
If you want to overcome SIGABRT, just ask for that too.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 95
Strange date stored 22 167
ShiftLeft challenge 21 88
Message not shown 5 82
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question