1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to split string into such array in C?

Discussion in 'Programming' started by ads2help, Apr 18, 2012.

  1. #1
    I am very new to C, which causes me headache as I have been working with Java all the time.

    I know string is array of char in C, but in this case that I am working on now, I need to convert this kind of string:

    cp file1 file2
    Code (markup):
    to such array (or what is this called?)

    char *arg[] = {"cp", "file1", "file2", (char *) 0};
    Code (markup):
    As I know this isnt a usual type of string, right? Because string is supposed to be array of char which only hold 1 char in each item.

    I need to convert that string to such "array" in order to use it in execvp() function:

    where cmd can be any command. It is "cp" in this case:

    execvp(cmd, arg);
    Code (markup):
    Any help? Thanks.
     
    ads2help, Apr 18, 2012 IP
  2. bomzas

    bomzas Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What you ought to use for this is an array of strings not an array of Chars. I only use C# and C++ myself so C is slightly a different format. Also you need to note if you're being passed in integer or floating point value numbers that you must convert them to strings either directly or indirectly
     
    bomzas, Apr 21, 2012 IP