0

How can I run another program from my c program in Windows 7? I am using dev-c++. This is my code:

#include<stdlib.h>    
#include<stdio.h>    
#include<conio.h>    

int main( void ) {    
    int result ;
    result=system("C:\Dev-Cpp\devcpp.exe\s");    
    printf("%d",result);
    getch();
} 
9
  • And what happens when you run the code? Commented Dec 9, 2013 at 7:13
  • Is "\s" some option for devcpp.exe? Commented Dec 9, 2013 at 7:23
  • 'C:Dev-Cppdevcpp.exes' is not recognized as an internal or external command,operable program or batch file. 1 >>>>This is my output.And thanks for quick respond. I will be careful about making question next time. Commented Dec 9, 2013 at 8:23
  • Be careful system on completion does not return the result of your program ( at least not in Linux ) linux.die.net/man/3/system Commented Dec 9, 2013 at 11:55
  • Plz. Give me a way by which i can solve this.>>>At least run my program correctly. Commented Dec 9, 2013 at 12:27

1 Answer 1

9

You will have to escape the backslashes in your call to system(). I'm also not sure what the trailing \s is for but it's probably a mistake. Try:

result=system("C:\\Dev-Cpp\\devcpp.exe"); 

the \ character has a special meaning when it is combined with the character after it. \n for example indicates a newline. In a string literal you need to write \\ to indicate you mean a literal backslash.

alternatively look at CreateProcess in the windows API for more control of the running process, especially if you don't want to block until it finishes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.