LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 05:42 PM   #1
madsovenielsen
Member
 
Registered: Aug 2009
Posts: 183

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, 05: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, 07:17 AM   #3
madsovenielsen
Member
 
Registered: Aug 2009
Posts: 183

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


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:37 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration