LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-24-2011, 06:42 PM   #1
madsovenielsen
Member
 
Registered: Aug 2009
Posts: 180

Rep: Reputation: 15
C Arguments to main - can't compare values


Whats wrong with this:
Code:
#include <stdio.h>

int main(int argc, char *argv[])
{
    if(argv[4] == "-verbose")
    {
        printf("Verbose is on");
    }  

  return 0;
}
I can use argv[4] in printf() just fine. But i can't compare the content of argv[] to anything.

Why ?

Kind regards Mads Nielsen
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 07-24-2011, 06:46 PM   #2
toredo
Member
 
Registered: Feb 2009
Posts: 83

Rep: Reputation: 25
You have to use strcmp to compare two c-strings.

With '==' you compare in your case only the strings addresses, which here are never the same.
An you should always check the parameters-count (argc).

best regards
toredo
 
3 members found this post helpful.
Old 07-25-2011, 08:17 AM   #3
madsovenielsen
Member
 
Registered: Aug 2009
Posts: 180

Original Poster
Rep: Reputation: 15
Thank you very much!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write command line arguments as values, into a file which contains variables sathiawathi.m Linux - Newbie 2 07-17-2009 03:27 AM
pass arguments and return values from a function in UNIX gaynut Programming 4 07-10-2008 02:56 AM
Compare Decimal Values rbautch Linux - General 10 04-22-2008 05:11 AM
How do I compare two values in separate files xmrkite Linux - Software 11 09-20-2007 12:36 AM
Streaming in values without defined command line arguments liguorir Linux - Software 1 05-07-2004 03:40 AM


All times are GMT -5. The time now is 07:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration