'How to start c app from desktop with double-click?

I have written one very simple app in C. I know how to run it through Visual studio, but i want to start it from desktop with a double-click. If I double-click on a .exe file made in folder, it does not start. How can I do this?

c


Solution 1:[1]

If you do not wish to modify your code so that it will wait for user input before closing (and there are many reasons that might be inappropriate), you could create a batch file wrapper:

myprog.bat


myprog.exe
pause

Then either you can double click the batch file or create a shortcut to the batch file then edit the shortcut to set the path to the batch file and the path from which to run (so it can find the exe).

That pretty much emulates how Visual Studio runs your code without terminating the window.

Another method you might consider is a batch file such as:

runner.bat


%1
pause

Then you can drag-and-drop your executable onto the runner.bat icon to run it. The advantage being that you don't have to create a new batch file and/or shortcut for every new executable.

Really though this is not a C question, or even a programming question - it is most likely off topic. If your code is ever required to run to completion unattended in a batch file for example, you would not necessarily want to add any interactivity to the program itself.

Solution 2:[2]

Your problem is that double clicking on a console app will open a new console window, run the program and then close the window.

VS studio does a trick where it runs the app in a new console window but keeps it open till you press a key.

You can add that same thing yourself - put a getchar() call at the end

Or you can make a bat file to run the app as per Cliffords answer

Solution 3:[3]

  1. 1st open the code with visual studio code
  2. Run or Build the program
  3. then u will find an executable file where u have saved your code
  4. Open that executable file

but you must have installed mingw installed in your environment

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 pm100
Solution 3