Solved

invoke a process with a single argument?

Posted on 2000-03-15
4
303 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

708 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

14 Experts available now in Live!

Get 1:1 Help Now