PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Thu Dec 07, 2006 5:40 am
Suppose I Want to Make A C Programm That Will Take An Integer Through Commandline And Out Put That Integer*5 And I'll Pass That Int Through php And Get The Answer Through php Then What Would Be The C Code To Build That Program ??
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Dec 07, 2006 5:44 am
Code: Select all
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
if ( argc > 1 ) {
long x = strtol(argv[1], NULL, 10);
printf("%ld", x*5);
}
return 0;
}
Can a moderator please move this thread to
Miscellaneous ?
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Thu Dec 07, 2006 5:50 am
Would You Please Tell Me How Does It Works ??
And How I Have To Pass That Integer Argument To It ??
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Dec 07, 2006 5:54 am
Arguments are available as an array of (zero terminated) strings to a C program.
argv[1] is the first parameter/argument passed to the program, e.g. yadda.exe firstArgument -> argv[1]<=>firstArgument
To convert a string to a number you may use strtol, see
http://msdn2.microsoft.com/en-us/w4z2wdyc(VS.80).aspx or your local msdn help.
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Thu Dec 07, 2006 6:05 am
Hello Sir
I Am Very Sorry To Post It In THis Forum But While Posting I Didnt Know
That The Topic Will Turn Like This
Would You Please tell Me How Can I Pass Two Arguments To That Program ?
Whats The Separator Is it Space Or comma
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Dec 07, 2006 6:06 am
volka wrote: the arguments are separated by whitespaces.
yadda.exe firstArgument secondArgument
access them via argv[1] and argv[2]
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Thu Dec 07, 2006 6:14 am
Then Whats The Work Of argc What Does It Do ??
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Dec 07, 2006 6:15 am
arg ument c ounter, the number of arguments.
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Thu Dec 07, 2006 6:17 am
How Can I Separate 2 or 3 arguments By Spaces Or By commas ??
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Dec 07, 2006 6:19 am
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Thu Dec 07, 2006 6:24 am
argv[1] is Assidned To The First Argument I Send
argv[2] is Assigned To The Second Argument I Send
Suppose My First Argument Is arg1 And Second Argument Is arg2
how Would I Write This ??
Like This
Or In some Other Way !!
ok
Forum Contributor
Posts: 393 Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land
Post
by ok » Thu Dec 07, 2006 6:24 am
There are some rules for passing arguments to a program. One of them is that the arguments have to be separated by signal space.
If you want to separate them by commas, you can do it, but in the program you will have to separate them (C won't do it for you!)
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Dec 07, 2006 6:25 am
a) already answered
volka wrote: yadda.exe firstArgument secondArgument
b) This one you really could've tried yourself.
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Thu Dec 07, 2006 6:26 am
So What is The Default Separator ??
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Thu Dec 07, 2006 6:27 am
Sorry
Ok So How Can I Separate The Input Arguments By a Comma ??