c programming, disable user input into terminal - c

Hi is there any possible way to temporarily disable user input into the terminal in c programming language?
There is probably a very good reason why you can't (possible malicious uses) but if its possible, can someone please illustrate how? maybe there is a function, a setting or even an obscure system command?
For context: a friend was having issues with a hard drive, so i created a program which ran a few terminal command and printed the output to a text file which he would send me. It all worked fine, however he didn't really know what he was doing so i printed instructions to the console to instruct him in what to do. although this all worked out, the thought did occur that i could potentially disable user input for that particular terminal window until it was required, and thus the question.
Its also a pretty basic question so if its actually a duplicate (although i could not find one) than please label as such.

Related

Beginner: How do I actually use gperf? It just hangs every time I run it

I am very new to coding, currently taking Harvard's CS50x class online. The extent of my familiarity with code, languages, and environments is what they've taught me so far in C. With vague guidance from other questions on this site, I've taken about 4 days to install gperf, from discovering what Cygwin is to installing all of its libraries and error-checking the installation all the way up to finding out where it finally put the installed program. I was so happy when I actually found the application 'gperf.exe' just now. I thought I was finally just about to get the hash function I've been trying to make for almost a week.
And now, the program does nothing but hang every time I try to run it, no error messages. Offering no input file causes it to hang. Doing any amount of and selection of options specified in the manual, it just hangs. Even debugging says it's entering debugging, then just hangs. The only way I've been able to get the program to respond at all is offering it an invalid input file, which it says is invalid. Nothing else does anything; no output file, no command-line response, nothing. I am frustrated to the point of tears, and the documentation provided with gperf assumes you're a professional coder, talking endlessly about the hundreds of high-level customization options to modify the program, but not a word about how to make it just run on a basic level. I've searched Google and this site extensively, and very little pops up as soon as I search for gperf related issues specifically.
Can anyone please just walk me through how to make this program work? I'm sure it's some stupid little thing that I'm missing, but all I want it to do is take my input file of strings and give me a hash function in C. Any and all help is appreciated, I have absolutely no clue what I'm doing and even installing gperf was a multi-day process that is far beyond the scope of what I've done so far.
Thank you.
EDIT:
Executions I've tried passing:
gperf
./gperf
Arguments I've tried passing:
-a
-c
-d
--output-file 'FILE'
I have tried all of these with and without the inclusion of my input file, named 'keys' and 'keys.txt'. The only thing that has generated any response from the program has been giving it an incorrect input-file name, giving the result 'could not load input file 'keys''.
gperf can be slow if the input file you give it is large, that is, contains many keys. You can get an impression of what are "small" files vs. "large" files by looking at the documentation: Known bugs and limitations.

How to i make a .bat that targets a program and types in a text box

I have no idea where to start on this one. I have seen answers that are like this but I don't know how to format them for what I want. I just need to target the minecraft server while its open and close it by typing "stop" in the console. I have no code to show for but this will be in a other file so I can launch it and then have it close the program. btw I don't think I can use taskkill But anything will help ;) thankyou very much!
This is not possible using a batch file alone. There are two main ways to get input to another program in the system (in this case, java.exe):
Get your program to listen for a special signal. There are several administrative plugins for Minecraft which will run in the Java process and will do what you need.
Spoof user input to the program. In the case of a console app, you would probably use a SendKeys() based solution. See How to send input to the console as if the user is typing for some examples.
In the case of Minecraft, I think the first solution is going to be significantly easier, because the modding community has already supplied a number of solutions to this exact problem. #Frxstrem recommended mcrcon, which I suppose is as good a solution as any.
Most probably the console client you are using is scriptable and this is not good aproach.
Any way here's a sendKeys.bat. You can use it like:
call sendKeys.bat "Minecraft console title" "stop{enter}"
Batch files can't do this without calling out to something else; if you're going to call to something else, use AutoHotkey - that's what it's good at.
WinActivate "the title of the Minecraft server window"
https://www.autohotkey.com/docs/commands/WinActivate.htm
Send stop{Enter}
https://www.autohotkey.com/docs/commands/Send.htm

Debugging using input file OS X

I searched for a solution to my problem already in Google and here in stack overflow.
I didn't found an understandable and precise solution for my problem:
I've written a program that maintains an inventory.
It compiled without warnings or errors and it works quite well when I type in commands by hand. When I'm running the program with an input file with much more parts I get a segmentation fault 11.
Now I want to debug my program but don't know how to do this using input files.
I already did some debugging via the CodeBlocks IDE. Didn't find a option for this.
I used malloc and realloc functions in my program and think the error happened there because I never used it before.
Could you please help me in following ways:
I need a debugger that can debug while the program runs with an input file.
The debugger must be able to check for memory leaks or things like this.
Thanks
Armin
Debugging with command line input vs. Debugging with a input file is the totally same.
You must understand this.
When you start debugging session in the IDE, it is by default 'no input' mode (no input file).
But you can specify startup conditions for the program, including working directory, command line arguments, etc.
By using these options, you can run the debugging session exactly same as user running the program with input files.

OS X Intercept Keyboard Events to Password Forms Elements

I am currently creating a c program that counts all of the keys I press in a day and sorts the key types by amount, so I can tell which ones I press most often. It was more of a side project than anything else but I have become annoyed with the fact that my program doesn't seem to be able to intercept any input to password fields. I suppose this is a good thing, but I have been spending hours looking at documentation and trying to figure how to do this. I am not trying to create any sort of malicious software. Is there a way around this? My program is running as root. I am using the ApplicationServices framework and CGEventRef and the CGEventTapCreate funcion. Should I be using a different framework or struct? Also, is there a difference between kCGHIDEventTap, kCGSessionEventTap, and kCGAnnotatedSessionEventTap? I have tried using each of them and it does not seem to make a difference in my program.
I am running this on OS X 10.9
UPDATE
Apparently I cannot capture keystrokes going to terminal either, which is where I spend most of my time on my laptop. This is a problem.
What you want is fairly complicated and requires a kernel extension. The interprocess communication is also not trivial. Take a look at logKext, specifically logKext.cpp. That project actually logs the keystrokes to an encrypted file. You should be able to pull everything you need from it.

Terminal app which takes up the whole terminal

I have been trying to figure out how to make an app similar to emacs in that when you run it, it runs in the terminal but it takes up the whole terminal and acts almost like a window. I can't find anything online about this, can anyone give me pointers of where to get started to figure this out?
For *nix, there is ncurses.
Wikipedia explains it to you: It is a library to write "GUI-like" applications in text format.
Also: Ncurses for Windows

Resources