?
Solved

Detecting ctrl-d while reading stdin

Posted on 1998-02-26
3
Medium Priority
?
550 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 150 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

801 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