Don't open console output with system() [duplicate] - c++

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Hide console in C system() function, Win.
Hi guys I have a little problem, I need to ping a lot of PC, so in my program i call the function system() with "ping -n 1 > tmp.txt", but I don't want that the console window is shown.
How can I do it?
P.S.: I use dev c++ :D
thx

It is fairly hard to do this cleanly.
A better approach might be to google "ping.c" and choose one of the many implementations, then rip the guts out of it and make your own ping function. This will be faster and give you more control.

I found what you might be looking for here Hide a window in C++
And also here I guess the freeconsole() method is what you are needing?

See this question :
Hide console in C system() function, Win

Related

Is it possible to decompile a C++ executable file [duplicate]

This question already has answers here:
Is it possible to "decompile" a Windows .exe? Or at least view the Assembly?
(16 answers)
Is there a C++ decompiler? [closed]
(5 answers)
Closed 4 years ago.
I lost the source code to an executable file but still have the actual file. Is there any way to retrieve the original C++ code?
Duplicate of this question here.
Yes, it is possible, however when it comes to peeking function bodies and the like, you might have a little less luck. Operating systems like Kali Linux specialize in de-compilation and reverse engineering, so maybe look into a VM of that. And of course, windows has a lot of applications you can use as well to check the application code.
Look over the other question for specific app suggestions. :)
Edit : You will most likely have lost all your logic and function bodies, but you might be able to recover the overall structure. It's your EXE so you might be more familiar with how it was all connected up.
You cannot get the original source code but you can decompile the binary into source code using tools given in this similar question: Is there a C++ decompiler?
The output source code will not look like the original as the compiler will have optimised the original source when generating the executable.
Short answer NO.
Long answer, because C++ doesn't use some intermediate code like C# or Java you cannot decompile the app in some readable format. But if you can read assembly maybe you can save some time.

Replacement for sync() command [duplicate]

This question already has an answer here:
Sync File System command for windows [closed]
(1 answer)
Closed 8 years ago.
I need to port one app on Windows. Originally that app was written on Linux and it uses Linux specific commands. I stacked at one place with sync(). Windows doesn't have such utility. The code looks like
QSettings *data
...
data->setValue("some_var", var);
data->sync();
sync();
That is a peace of C++ file. I don't know C++. It was written not by me. I use other languages. So how can I make it work on Windows or how can I rewrite that part?
Basically you can ignore the system-specific sync() call. It's not needed, even on linux. QSettings does the right thing for you.
If you have access to all the files you have open, I believe the equivalent of calling sync() on Linux is the same as going over all the file handles and flushing them on Windows, probably by using FlushFileBuffers().
EDIT 1
If you're using the C file interface (since you came from Linux), fflush() is your friend (you still need to have access to all open files.)
EDIT 2
I see there is a _flushall() call you can use. Not sure about its similarity to Linux's sync() but they generylly seem to do the same thing. I'm also a little wary about using functions that start with underscore.

C++ detecting keystrokes [duplicate]

This question already has answers here:
Capturing a keystroke in C++
(4 answers)
Closed 9 years ago.
I am trying to use keystrokes to affect my program. For example, I have a program that prints numbers continuously. I want it to stop printing numbers if I enter Ctrl+E. How can I do this on C++?
I have read about a number of headers like conio.h but they are not built in the C library. I would like this to be kept as pure C/C++ as possible.
you can use GetAsyncKeyState function for this.
It is there in Winuser.h file
That depends on the operating system - hence impossible in 'pure' C/C++.
I fear you have to go with #ifdef SYSTEM_A, ...
Please notice, The languages C/C++ are not aware of any kind of hardware (keyboard in this case), they know streams.

Is there any software to format source code for C/C++ on Mac? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Objective-C style formatter
I have wrote a program and wonder if there is any software to format the codes the way it should look like a good programmer?
I know I shouldn't rely on it but just for my curiosity and to have this done in a better way because my code it so mess up and I want it look nicer and better.
On mac would be appreciated if not PC would be okay.
If you're using XCode, you can re-indent your files (Editor -> Structure -> Re-Indent), or with the keyboard shortcut: ControlI.
One nice code formatter is astyle. The download link can be found here. And I just checked, they support Mac as well.
There's the command-line program indent, which does not do complete style formatting but does get indentation sorted out for you. indent should come with your Mac (or maybe it comes with Xcode? not sure). See man indent.

automatically skipping/ignoring external code in gdb [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to avoid entering library's source files while debugging in Qt Creator with gdb?
anybody know how to tell gdb to only enter code that is in your project? I know it's hard for a debugger to know what is "in the project" and what is a library....but I thought some naive checks could help, eg don't look in any files that aren't in the users home directory. I frequently have code like this:
MyFunction(complexVarable, complexvar); //passed by value
and gdb insists on going through the copy constructors of the two passed values, but all I care about is MyFunction. Any tips? There are two parts to the question,
ignore code that isn't mine (not in home dir)
skip copies for function calls.
thanks.
EDIT: btw I use emacs, maybe there are some tools there I missed, but I'm open to using external gdb frontends.
As per my opinion this cannot be done.
every project has a flow of data from one function to other.
gdb is designed to work on the flow of data.
so if your project is somewhere in the middle of the flow,gdb cant help you,since evry function has some purpose to do with the input it gets and output it gives.
all you can do is create the same function separately and replicate the scenario as if its running in teh flow by giving the inputs it needs and output it gives.