How to run an exe using c prog

Posted by Ujjwal on Stack Overflow See other posts from Stack Overflow or by Ujjwal
Published on 2011-01-16T13:58:42Z Indexed on 2011/01/16 14:53 UTC
Read the original article Hit count: 249

Filed under:

Hi All,

I am new to this forum. I am in need of a program in C that runs an exe file in Windows. While googling I found the code below :

1. Code:

#include<stdlib.h>
#include<stdio.h>
int main()
 {
  (void)system("C:\\Windows\\notepad.exe");
   return 0;
  }

The above code compiles successfully in Borland Turbo C. But it fails to run Notepad.

2 Code:

#include<stdlib.h>
#include<stdio.h>
void main()
 {
  int result ;
   result=system("C:\\Windows\\notepad.exe");
   printf("%d",result);

  }

The above code on running gives -1 as output. Why am I getting -1.

My OS Windows XP Borland Turbo C Compiler

Please help.

© Stack Overflow or respective owner

Related posts about c