CrazyEngineers Archive
Old, but evergreen and popular discussions on CrazyEngineers, presented to you in read-only mode.
@bharathkumarp • 07 May, 2010
Hi CEans, in c language,is there any possibility to call another program from main program....?
@saurabh2486 • 10 May, 2010 Re: C program doubt..

i think yes its possible
@sherya mathur • 10 May, 2010 Re: C program doubt..

I will also go with saurabh
yes it is possible in c language to call another program from main program
@gaurav.bhorkar • 10 May, 2010 Re: C program doubt..

saurabh2486
i think yes its possible
sherya mathur
I will also go with saurabh
yes it is possible in c language to call another program from main program
Can we know how this is done?
@ms_cs • 10 May, 2010 Re: C program doubt..

Just make that file as header file and include it in the new file in which you want to use that file..thats it
@bharathkumarp • 10 May, 2010 Re: C program doubt..

will you please provide me simple program code....
@gaurav.bhorkar • 11 May, 2010 Re: C program doubt..

Ah! now I remember,

If you want to run a program within a terminal using a C program, you can use the standard library function system ().

Suppose we want to run the program "hello.exe", here's how we can do this,
int main ()
{
    printf ("Before calling a program \n");
    system ("hello.exe");
    printf ("After calling the program \n");
    getch ();
    return 0;
}
@bharathkumarp • 13 May, 2010 Re: C program doubt..

hi Gaurav, i executed the code which are provided by you.. It's executing only the printf statements but it not executing the block which are inside system.... Is there any header i need to include????
@gaurav.bhorkar • 13 May, 2010 Re: C program doubt..

bharathkumarp
hi Gaurav, i executed the code which are provided by you.. It's executing only the printf statements but it not executing the block which are inside system.... Is there any header i need to include????
Yes, you have to include stdlib.h for system() to work.
@bharathkumarp • 13 May, 2010 Re: C program doubt..

HI Gaurav, this is also not working.. Only the printf statements are working...Without stdlib.h also it's showing the same output....
@mayank1055 • 14 May, 2010 yup it's not working
@gaurav.bhorkar • 15 May, 2010 It works perfectly in Visual C++ Express Edition 2008.
@bharathkumarp • 15 May, 2010 ok, i'll check it out... Thanks for the code...
@silverscorpion • 17 May, 2010 Did you create the hello.exe file? Do you have it in the same directory?
@gaurav.bhorkar • 17 May, 2010
silverscorpion
Did you create the hello.exe file? Do you have it in the same directory?
Yes the hello.exe file and our calling program's file should be in the same directory.

The hello.exe must be created, it can have anything like printf ("Hello World \n").
@bharathkumarp • 17 May, 2010 ya i put the file inside the same directory,but it is not working.....
@gaurav.bhorkar • 17 May, 2010
bharathkumarp
ya i put the file inside the same directory,but it is not working.....
Which compiler are you using?

If you are using VC++, then your program's executable is in the debug directory. That is, My Documents/Visual Studio/Projects/<projectname>/Debug.

Now paste the hello.exe into this directory.
5.5k views

Related Posts

@harpreetbrar · Jul 7, 2009

Hello CE's, This is about my summer term project. I want to worked on RTOS based project. but i am confused...😕 I require the following information: 1. where can i...
6.3k views

@Ambarish Ganesh · Sep 23, 2013

The latest Skoda Octavia sedan shall celebrate its India launch on 3rd October this year. Officially announced in August, the 2013 Skoda Octavia is slated to hit the Indian market...
6.6k views

@Ankita Katdare · Jun 3, 2013

Samsung Electronics Corp. has today launched a new tablet called the Samsung Galaxy Tab 3, the successor to its early Galaxy Tab 2, to be made available globally starting this...
9.8k views

@Ankita Katdare · Feb 19, 2015

ISRO's Mangalyaan or Mars Orbiter Mission has been a topic of regular discussion over the last couple of years. Right from November 2013, when Indians wished it a 'happy journey',...
4.7k views

@durga ch · Oct 23, 2013

ok, though everything else works fine, I had an issue while accessing VM. The network adapter 1 ( attached to NAT ) is just fine. But the problem is with...
14.8k views