I have written a very simple C program with a GTK interface that has allows the user to load an input file.
On some Windows 10 computers, the program crashes without showing any error window while trying to read the input file. But on other computers, it reads files just fine.
Is there a known cause for this kind of inconsistent behavior on Windows?
Related
I have made a c program with codeBlocks on windows 10, but the exe crashes as soon as I open it, actually it does not matter the program all exe produced by codeblocks won't run, maybe there are some problems with the settings? Cause if I run the program from inside codeBlocks it runs without problems, any suggestion?
You are compiling "command line programs", which don't open a window on their own. Since they apparently don't expect any user input they run to the end quite happily and quit.
If you want to run this type of programs, you need a shell, which provides a window.
This is a simple way to get one: Open a file explorer window and navigate to the directory containing your program. Click into the address bar so that it changes into a textual representation of the path. Replace all of it with the word cmd and press enter. Now the shell's window opens, commonly with white text on a black background. Enter the name of the program, and it will run.
We all know the basic Hello World program:
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
This will open up a command prompt and show us the "Hello, World" message.
My question is: Why? Why is the message shown in a command prompt and not in notepad for example? Why not as a Windows notification? Why is it specifically the command prompt and not something else?
When you “open” a file through Window’s File Explorer, the system (not necessarily the OS directly; various subcomponents are involved) examines the file. If it is a native Windows application, the system will execute it directly. If it is another kind of file, the system will look up an appropriate application for it. For example, if it is a Microsoft Word file, the system will start Microsoft Word with a request that it open the file.
If the file is a “command line” program, the system will start Windows Terminal (or similar program in various versions of Microsoft Windows) with a request to run the program. More specifically, it may start Windows Terminal with a request to run a particular command-line shell and to have that shell run your program.
The C language grew up in Unix-like environments where a command shell read input from a physical keyboard and write output to a physical display. In modern systems, these are usually replaced by pseudo-devices that perform the same functions in software. When the shell starts a command-line program, it creates a new process with the standard input and standard output streams of that process connected to the pseudo-device that provides the keyboard/display functions. (This is the default. You can also request a shell to start a program with input and output redirected from/to files and other devices.)
Then, when your program writes to standard output, it goes to the pseudo-device, which relays the data to the appropriate parts of the system that cause the text to be displayed in the terminal window.
I am using eclipse cdt oxygen with mingw64 7.2.0 on windows 10 to write programs in c. Whenever I write programs that only outputs like:
printf("x\n");
The output got printed into the console. However when I write programs that asks for inputs, like:
c = getchar();
rather than going to the console, eclipse instead opens a terminal. I believe that is where you will type the input. This doesn't usually bother me, however my eyes are destroyed, I am using a screen reader and this terminal is somewhat inaccessible. It is usable, but can be very hard to use sometimes (E.G. my screen reader JAWS does not speak what I'm typing).
Is there a way for eclipse cdt to put all inputs and outputs directly to the console?
Unfortunately in this case eclipse console is read only. Better once compile and build your code go to the folder where it created your exe file and run that exe in command prompt and test.
open command prompt window (type cmd)
cd C:\path_to_your_exe\
yourexe
This will also help you in case your program takes command line parameters.
I had to write code in C and run it for an assignment. Since this is the first time that I'm using C, I downloaded MinGW as a compiler and Code Blocks as an IDE. I had no problem compiling the code given by my professor but it never runs (this is a simulation for an M/M/1 queue). When I say it never runs, I mean that a command prompt like window pops up and nothing happens after that. Every time I close that window and try to compile the SAME program again, I get an error that says that permission to access the file has been denied.
I then deleted Code Blocks and tried running the program through command prompt but I have the same problem. I've now tried doing it using LCC-Win but nothing has changed. Another weird thing that happens when I run any program is that three instances of the .exe file of that particular program are in my processes under task manager. I then need to restart my computer to try compiling that same program.
I even tried running a simple Hello World program and I have the same problem!
I am currently using a Windows 7 32-bit system.
Any help would be greatly appreciated!
I am trying to write a icon changing program like resource hacker. I am able to change icons of windows programs but not console programs and I think thats quite obvious. So I want to write a code in my program that will check if the argument exe file is a console program or windows program before it tries to change the icons.
So how do I check if an exe file is a console program or windows program. I am writing program in C using visual studio.
The Subsystem value inside the Portable Executable header of the file will give you the info:
WINDOWS_CUI 3 Runs in the Windows character subsystem (a console app)