Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Calling programs from c++  (Read 2955 times)

0 Members and 1 Guest are viewing this topic.

d-boy22

    Topic Starter


    Rookie
    Calling programs from c++
    « on: December 18, 2009, 01:44:11 PM »
    Im trying to call a program from my c++ program, ive got it to work if i put the program im calling in c:/ but if i put it in a folder with a space in its name like 'C:/Program Files' it doesnt see anything after the space, if there is a better way to call programs please let me know. Help will be greatly appreciated.

    #include <iostream>
    #include <cstdlib>

    using namespace std;

    int main()
    {
        cout <<"enter: ";
        char a[100];
        cin.getline(a , 100);
        system(a);
       
    system("pause");
    }

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Calling programs from c++
    « Reply #1 on: December 18, 2009, 03:40:22 PM »
    use quotes around the filename.
    I was trying to dereference Null Pointers before it was cool.

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Calling programs from c++
    « Reply #2 on: December 18, 2009, 10:12:16 PM »
    Boy, my eyesight is very bad.
    I can't find the file name that is not in quotes.

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Calling programs from c++
    « Reply #3 on: December 18, 2009, 10:17:49 PM »
    Boy, my eyesight is very bad.
    I can't find the file name that is not in quotes.

    Quote
      system(a);

    should be system(strcat("\"",strcat(a,"\"")))

    or something along those lines. regardless... whatever is in a should be quoted.
    I was trying to dereference Null Pointers before it was cool.