• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

invoke a process with a single argument?

how can I invoke a process with a single argument
on the command line representing a number?
I mean,   the filename of the program is "game.c"
how can I input "game 1234"  to invoke this program
instead of inputting:
game
1234

Thanks!
0
huhulucy90
Asked:
huhulucy90
1 Solution
 
ozoCommented:
#include <stdlib.h>
#include <stdio.h>
void main(int argc, char *argv[]){
  int number;
  if( argc != 2 ){
      printf("usage: %s 1234\n",argv[0]);
      exit(EXIT_FAILURE);
   }
   number = atoi(argv[1]);
   printf("%d\n",number);
   exit(EXIT_SUCCESS);
}
0
 
terajivCommented:
Hi,
invoke a process with a single argument...
U want the command line arguments and the example of which is given above by ozo. That is fine.
Have a Nice time...

Rajiv
0
 
ntdragonCommented:
yeah you should use ozo's code for taht
and it you want to execute it from your prog use the command execl(...)
the "1234" goes as a parameter
0
 
huhulucy90Author Commented:
Thank you!
surprised to see the answer this fast!
so happy to find this place!
Lucy
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now