Thread: passing values

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    291

    passing values

    I need some help passing two variables to another program.

    Code:
    void create_process(char* prog_name, int userID, processID)
    {
      // code
      // I need to convert the two int's to char to send them...??
      execl(prog_name, prog_name, userID, processID,0);
    }
    
    //
    int main(int argc, char *argv[])
    {
      int userID, processID;
      // convert argv[0] into userID and argv[1] into processID
      //code
    }
    From what I can figure out I need to convert userID and processID to char to be able to send then to another program and then I need to convert them back into int's again but I dont know how. Please help.

  2. #2
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    argv[0] is nothing; argv[1] is the first passed argument
    hello, internet!

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    look up sprintf and snprintf.

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Originally posted by vVv
    Just in case you take your own function's name serious - it doesn't create a new process, the old one is just replaced (common mistake to assume otherwise) so when the program you execute exits, your process is gone, too. So make sure you fork( ) off a /real/ new process and have that call execl( ) (man 2 fork).
    Yeah I've done the fork() thing

    sscanf and sprintf seem to have done the trick thanks. Part of the problem is I thought argv[0] was the first element.

    Another question, if I want to read what the user is typing on the keyboard what command(s) are recommended ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing Objects, Constructors, Pointers, References, Values ???
    By BlackSlash12 in forum C++ Programming
    Replies: 24
    Last Post: 12-14-2007, 06:26 PM
  2. Passing integers to escape values
    By AmbliKai in forum C Programming
    Replies: 2
    Last Post: 11-09-2007, 08:35 AM
  3. Passing Values Question...
    By tinkerbell20 in forum C++ Programming
    Replies: 9
    Last Post: 06-27-2005, 11:33 AM
  4. ascii values for keys
    By acid45 in forum C Programming
    Replies: 2
    Last Post: 05-12-2003, 07:13 AM
  5. passing values in array
    By xenodvs1 in forum C Programming
    Replies: 3
    Last Post: 02-12-2003, 01:50 PM