* processing arguments
@ 2004-04-23 21:44 ameer armaly
2004-04-24 0:40 ` Chuck Winters
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: ameer armaly @ 2004-04-23 21:44 UTC (permalink / raw)
To: linux-c-programming
Hi all.
Let's say that I have the following c++ code:
#include <iostream>
int main(int argc, char *argv[])
{
if(argv[1]=="hello")
cout <<"Hello World!";
return 0;
}
When I try that, and I type:
./a.out hello
It doesn't give me any output.
Can someone explain how to process args properly?
Thanks,
Ameer
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: processing arguments
2004-04-23 21:44 processing arguments ameer armaly
@ 2004-04-24 0:40 ` Chuck Winters
2004-04-24 0:58 ` A. Murat Eren
2004-04-24 5:06 ` vadiraj
2 siblings, 0 replies; 4+ messages in thread
From: Chuck Winters @ 2004-04-24 0:40 UTC (permalink / raw)
To: linux-c-programming
Ameer,
Your if stmt:
if(argv[1] == "hello")
is only comparing the pointer values in memory. You need
to use strncmp(3) to do comparison on strings.
Chuck
On Fri, 2004-04-23 at 16:44, ameer armaly wrote:
Hi all.
Let's say that I have the following c++ code:
#include <iostream>
int main(int argc, char *argv[])
{
if(argv[1]=="hello")
cout <<"Hello World!";
return 0;
}
When I try that, and I type:
./a.out hello
It doesn't give me any output.
Can someone explain how to process args properly?
Thanks,
Ameer
-
To unsubscribe from this list: send the line "unsubscribe linux-c-
programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: processing arguments
2004-04-23 21:44 processing arguments ameer armaly
2004-04-24 0:40 ` Chuck Winters
@ 2004-04-24 0:58 ` A. Murat Eren
2004-04-24 5:06 ` vadiraj
2 siblings, 0 replies; 4+ messages in thread
From: A. Murat Eren @ 2004-04-24 0:58 UTC (permalink / raw)
To: ameer armaly; +Cc: linux-c-programming
Hi,
> if(argv[1]=="hello")
man strcmp
you can not compare strings like yours..
regards, murat.
--
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
A. Murat Eren
meren@comu.edu.tr, evreniz@core.gen.tr
http://zion.comu.edu.tr/~evreniz/
0x88FD9FC7,
910A FCB3 2AAB 4CA5 E4D9 EFFA 6555 A33A 88FD 9FC7
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
--
free software is a matter of liberty,
not price. to understand the concept,
you should think of "free speech",
not "free beer".
-
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: processing arguments
2004-04-23 21:44 processing arguments ameer armaly
2004-04-24 0:40 ` Chuck Winters
2004-04-24 0:58 ` A. Murat Eren
@ 2004-04-24 5:06 ` vadiraj
2 siblings, 0 replies; 4+ messages in thread
From: vadiraj @ 2004-04-24 5:06 UTC (permalink / raw)
To: ameer armaly, linux-c-programming
Hi,
> When I try that, and I type:
> ./a.out hello
>
> It doesn't give me any output.
> Can someone explain how to process args properly?
> Thanks,
args are no special data type, they are just two dimenstional char array,
all the strings functions apply to them. Like the others mentioned
string compare should be done either charecter by charecter or use the
lib function on strings.
cheers,
Vadi.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-04-24 5:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-23 21:44 processing arguments ameer armaly
2004-04-24 0:40 ` Chuck Winters
2004-04-24 0:58 ` A. Murat Eren
2004-04-24 5:06 ` vadiraj
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).