how to add variables to the system command

This is a discussion on how to add variables to the system command within the C Programming forums, part of the General Programming Boards category; is there any way to do it.Like say I wanted to create a directory with the same name as the ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    16

    how to add variables to the system command

    is there any way to do it.Like say I wanted to create a directory with the same name as the vaiable x.I've tried system("mkdir %s",x) but it didn't work.
    Last edited by angelfly; 10-05-2001 at 05:48 PM.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Use the sprintf() command to put your variables into a string, then pass that string.

  3. #3
    Registered User *pointer's Avatar
    Join Date
    Oct 2001
    Posts
    74
    The declaration of system is
    int system(const char *string)

    So it would stand to reason that you might be able to do something like this:
    Code:
    char s1[20] = "MKDIR";
    char s2[20] = '\0';
    
    scanf( "%s", s2 );
    strcat( s1, s2 );
    system( s1 );
    pointer = NULL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. the system command
    By happyclown in forum C Programming
    Replies: 7
    Last Post: 01-02-2009, 06:14 AM
  2. Replies: 6
    Last Post: 07-21-2008, 03:10 AM
  3. Add system specs to profile?
    By psychopath in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 05-02-2007, 03:55 PM
  4. Using Variables with th 'System' command
    By dapernia in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2003, 05:11 PM
  5. Putting variables in SYSTEM
    By mycro in forum C++ Programming
    Replies: 3
    Last Post: 05-29-2003, 07:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21