Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Detecting ctrl-d while reading stdin

Posted on 1998-02-26
3
Medium Priority
?
567 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

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

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…
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.
Loops Section Overview
Suggested Courses

610 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