Results 1 to 6 of 6
hi..
im trynig to write a program that will catch when the user types in ctrl+d and i ctrl+L...so when im waiting to input and catch it using fgets() or ...
- 04-01-2008 #1Just Joined!
- Join Date
- Oct 2007
- Posts
- 60
CTRL+D and CTRL+L signal handling
hi..
im trynig to write a program that will catch when the user types in ctrl+d and i ctrl+L...so when im waiting to input and catch it using fgets() or some other function, i want to check if its ctrl+l or ctrl+d, how can i do that?..coz strcmp() can't check for such things..at least i dont think so..
and if these two keys generated a signal, then i should handle them using signal() function, but i dont know what signals they generated..i.e. ctrl+c generates a SIGINT..but i dont know what ctrl+d and ctrl+L generate..
any help would be appreciated..thanks..
- 04-01-2008 #2
If you're using fgets() or another standard I/O function to get your input, you won't see the ^L until the user enters some sort of end of line character.
Further, neither ^D nor ^L ordinarily generates a signal.
If you wish to have more fine-grained control, there are other functions you should use instead for your keyboard input. Do this at the command line:
If you do not have man pages installed on your system, google for this:Code:man tcgetattr man tcsetattr man 2 read
Hope this helps.Code:man tcgetattr linux man tcsetattr linux man read linux
--
Bill
Old age and treachery will overcome youth and skill.
- 04-01-2008 #3Just Joined!
- Join Date
- Oct 2007
- Posts
- 60
i know how to use the termios library, but the problem is that even if i use the termios functions, i still don't know what to check for..i mean ok so i use the termios to read a string, and then i want to check if this string is ctrl+l or ctrl+d, what are their hex values?
- 04-01-2008 #4
They're individual characters, not strings.
^A is 0x01.
^B is 0x02.
And so on through the English alphabet.--
Bill
Old age and treachery will overcome youth and skill.
- 04-02-2008 #5Just Joined!
- Join Date
- Oct 2007
- Posts
- 60
ok ctrl+L turned up to be 0x0C, and i tried using scanf, any stdin function to get the char and check if its ctrl+L and it worked using its hex value, but ctrl+D sends some kind of signal to terminate the process im working in..
i.e. the execution of this program works fine:
but the execution of this doesnt..Code:#include <stdio.h> int main() { char c; printf("Write: "); scanf("%c", &c); if(c == 0x0C) printf("ctrl+L was entered\n"); return 1; }
ctrl+d sends some kind of signal to terminate the process..but i thought it only sent a signal to kill a terminal process when its running...so how can ctrl+d be checked?..by signal()?..and if by signal(), whats the signal ctrl+d generates?..thanks..Code:#include <stdio.h> int main() { char c; printf("Write: "); scanf("%c", &c); if(c == 0x04) printf("ctrl+D was entered\n"); return 1; }
- 04-02-2008 #6Don't use standard input. Use the functions I mentioned here.how can ctrl+d be checked?--
Bill
Old age and treachery will overcome youth and skill.


