system call

This is a discussion on system call within the C Programming forums, part of the General Programming Boards category; Is it possible to do a system call with a string as part your input. char file[100]; system("vi file");...

  1. #1
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195

    system call

    Is it possible to do a system call with a string as part your input.

    char file[100];

    system("vi file");

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I believe you'd need to concatenate the command into one char array first, then pass that as the arg to system().

    Something like
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        char fn[] = "a.c";
        char buffer[1024];
    
        strcpy(buffer, "vi ");  // Should really use strncpy and strncat
        strcat(buffer, fn);
    
        system(buffer);
        return(0);
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Unregistered
    Guest

    Smile

    works like a charm, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 09:25 AM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 06:18 AM
  3. Inline asm
    By brietje698 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2007, 01:54 PM
  4. nanosleep() -system call does some confusing things
    By jtk in forum Linux Programming
    Replies: 5
    Last Post: 08-30-2007, 04:15 AM
  5. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM

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