Solved

Detecting ctrl-d while reading stdin

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

12 Experts available now in Live!

Get 1:1 Help Now