Solved

invoke a process with a single argument?

Posted on 2000-03-15
4
304 Views
Last Modified: 2010-04-15
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
Comment
Question by:huhulucy90
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 48 total points
ID: 2621616
#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
 
LVL 3

Expert Comment

by:terajiv
ID: 2622218
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
 
LVL 1

Expert Comment

by:ntdragon
ID: 2622490
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
 

Author Comment

by:huhulucy90
ID: 2624153
Thank you!
surprised to see the answer this fast!
so happy to find this place!
Lucy
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now