Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-24-2011, 05:42 PM   #1
Registered: Aug 2009
Posts: 180

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

Whats wrong with this:
#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, 05:46 PM   #2
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
3 members found this post helpful.
Old 07-25-2011, 07:17 AM   #3
Registered: Aug 2009
Posts: 180

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


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 02:27 AM
pass arguments and return values from a function in UNIX gaynut Programming 4 07-10-2008 01:56 AM
Compare Decimal Values rbautch Linux - General 10 04-22-2008 04:11 AM
How do I compare two values in separate files xmrkite Linux - Software 11 09-19-2007 11:36 PM
Streaming in values without defined command line arguments liguorir Linux - Software 1 05-07-2004 02:40 AM

All times are GMT -5. The time now is 12:26 AM.

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