#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    7
    Rep Power
    0

    Question Problem with system()


    Hello friends,

    i am using the code below :

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <string>
    #include <iostream>
    
    using namespace std ;
    
    int main(void)
    {
        char szInput[256];
        string name ;
        printf ("Enter the file name: ");
        gets (szInput);
        name = szInput ;
        
        system("ls name");
        return 0;
    }
    the system() functon does not recognize the string name or what the user typed, but it is trying to do ls in the file with the name name .


    any help please.

    Thank you very much .
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2007
    Location
    Zografos, Greece
    Posts
    52
    Rep Power
    11
    Well, since everything inside the double quotes is a string, the variable name is not recognized.

    Use strcat to concatenate the command to a new variable and then use the system function.

IMN logo majestic logo threadwatch logo seochat tools logo