Solved

Detecting ctrl-d while reading stdin

Posted on 1998-02-26
3
499 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GIF file bit manipulation for color change 5 107
unable to delete all specified values regedit 38 278
NotAlone Challenge 20 80
canBalance challenge 34 70
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now