Compile a C program using Command prompt - compilation

My Task-Finding Area of a circle using command line interface in windows. I created a file named circle.c and tried to compile with command prompt. But shows error as -'cl' is not recognized as an internal or external command, operable program or batch file-.
I tried searching in the web. It shows me to open Developer command prompt. But I don't have any Visual Studio installed on my pc.
How can I run this program using command line interface?
#include<stdio.h>
#include<conio.h>
int main(int argc,char *argv[])
{
float Diameter=atoi(argv[1]);
float radius=D/2;
float area=(radius*radius)*3.14;
printf("The area is %0.2f",area);
return 0;
}

Related

Why using WriteConsoleA in mingw has no output?

I am trying to compile on mingw a program that prints to console using Windows.h functions. Why do I get no output?
C file:
#include <Windows.h>
int main() {
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsoleA(out, "hello", 5, NULL, NULL);
return 0;
}
To print to a console your application must be a console application in the first place. A Windows GUI application can
Make sure you linked the application using the -mconsole flag.
Also make sure that you are not running the application from somewhere where the output may disappear right away (like an IDE). Instead open a command prompt and run your .exe file from there to see the output. Or you could add some code to wait for a key in your code so you can see the output before the window closes automatically.

How to make one executable file that has a bash script and dependency files?

Here is my bat script (TestBatScript.bat):
set /p args=Enter some args:
TestApp.exe %args%
pause
For this script to work I have to have TestApp.exe and TestBatScript.bat in the same folder. Is it possible to include these two files in one file .bat or .exe or whatever?
If this is what you are asking for, you can't aggregate batch file with exe file. Indeed exe file are compiled file (open it on a text editor, you won't be able to read it). Batch files are scripts that are interprated by terminals.
If you can recompile your exe file, you can add to source code to pass argument with hands (for instance use scanf in C, ...) if there is no argument passed by the system
int main(int argc, char** argv) {
if(argc==0) {
/* get here the argument (no argument passed)*/
}else {
/* use here argument passe to your function */
}
/* Do stuff */
}
You can use Iexpress that is a built in program in your windows OS. To access it hir win+R and then type iexpress or iexpress.exe. Do some experiments and you will eventually understand. Here is the Wikipedia in case want it. And Here is a tutorial on How to use it.

gcc-Mingw compilation error on cmd

i install gcc-mingw on windows 32 bit for c programming languauge .. i install first time in my laptop so when i open notepad file and save this file on desktop with the name of hello.c
#include <stdio.h>
int main()
{
/* my first program in C */
printf("Hello, World! \n");
return 0;
}
then when i open command prompt and enter
gcc hello.c -o hello
then it shows error
gcc:error:hello.c:no such file or directory
gcc:fatal error:no input files
compialtion terminated
how to solve this error?
I suspect your are running the command from a different folder than the one your hello.c file resides

system command not running exe file using variable as param

I am writing code to download an app from server in visual studio 2005(VC++). After downloading it when I start running it line 3 does not run the exe file while if I write it as
system("c:/pg/ap/app.exe")
it starts running.
Can anybody tell me why this is happening?
1.const char * str;
2. HRESULT hr = URLDownloadToFile ( NULL, _T("file_path/app.exe"),(LPCWSTR)str,0,NULL);
3. system(str);
Rather then using System() function, try ShellExecute(), it ll solve your problem.
For more help refer this

Cannot connect creator comm socket /tmp/qt_temp.JH2103/stub-socket: No such file or directory

I'm getting this error when I run a console-based project from Qt Creator in Kubuntu. The Konsole terminal pops up but it only says:
Cannot connect creator comm socket /tmp/qt_temp.JH2103/stub-socket: No such file or directory
Press <RETURN> to close this window...
I had the same problem in Ubuntu 11.10 after installing Qt Creator with apt-get. If you will go to Qt Creator settings and change the terminal to /usr/bin/xterm -e then it should work.
This one works for me.
Menu | Tools | Options | Environment | General | System | Terminal
konsole --nofork -e
You can follow these steps to make the change:
Tools > Options > Environment > General > System > Terminal: xterm -e
The Qt Creator does not support a full terminal in its GUI/
Console applications started from the creator display their
output in a window of the creator. This window does not
support cin. To handle such programs they must be executed in
an actual terminal. Also under linux the correct terminal
program must be specified in the creator settings.
Set program execution to be in terminal in Qt Creator:
1 - In the left icon bar: press “Projects“
2 - In the area “Run Settings“: press “Show details“
3 - Check “Run in terminal“
Set terminal in Qt Creator for linux:
1 - Menu: Tools -> Options...
2 - Select “Environment“ -> “General“
3 - Set text for “Terminal:“ to “/usr/bin/xterm -e“
4 - Press “OK“
And you are done.
I ran into this same issue and it turned out I had too many instances of my console application running in the background. I left my settings to gnome-terminal -x and instead just closed all the running instances of my application then tried again and it worked.
If you still want to use konsole, this may be due to one of its settings. In Konsole, click Configure->Configure konsole-> Untick Run all Konsole windows in a single process.
Changing the terminal settings under Tools->Options->Environment->System->Terminal to /usr/bin/xterm -e worked for me on Ubuntu 13.10
This "Cannot connect creator comm socket /tmp/…/stub-socket: No such file or directory" error appeared for me when you I tried to run my project in debug mode.
It was a basic project to get started using Qt with opencv (Load image file). I took me a while make it run.
the .pro file cotains:
QT += core
QT -= gui
TARGET = Hello
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += "/usr/local/include/opencv"
LIBS += `pkg-config opencv --libs`
the main.cpp file contains:
#include <QCoreApplication>
#include <QDebug>
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
// QCoreApplication a(argc, argv);
//qDebug()<<"hello world";
Mat image;
//image = imread(argv[1]); // Read the file
image = imread("/home/maalej/AhmedWork/maalej.jpg");
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
qDebug()<<"hello world";
cout<<"**********"<<endl;
namedWindow( "Display window" );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0);
return 1;
//return a.exec();
}
When running the qtcreator installed manullay after downloading it from the official website, any printed string appears in the console but not the image!!! Even with changing from /usr/bin/xterm -e to x-terminal-emulator -e .
I uninstalled the qtcreator by running the qtcreatormanitenancetool and pressing uninstall all.
I reinstalled qtcrator using ubuntu software center (recommended to install packages properly).
I runned my project still nothing, but when changing the default setting x-terminal-emulator -e to /usr/bin/xterm -e, it worked and the image is loaded.
thank you Alexander.

Resources