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 08-13-2003, 05:55 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
Print statement never executed


Print statement never executed

./getdata long

=========================================
Code:
#include <stdio.h>  
#include <stdlib.h> 

char *progam_name;
char *parameter1;

main(argc, argv)
  int argc;
  char *argv[];
 {
    progam_name = argv[0];
    parameter1  = argv[1];

    if (argc < 2)
      do_process_1();
    else
      if (argc == 2 && parameter1 == "long")
PROBLEM -->>          printf ("parameter1 = %s\n", parameter1);
 }
 
Old 08-13-2003, 06:14 PM   #2
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
actually the problem is the line above, you cant compare strings like that, refer to this thread http://www.linuxquestions.org/questi...590#post422590 the required modification is

if( argc == 2 && !strcmp(parameter1, "long"))

strcmp is defined in string.h
 
Old 08-14-2003, 12:28 PM   #3
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
to kev82

Hi. the statement below
if( argc == 2 && !strcmp(parameter1, "long"))

When there is two argument and parameter1 is equal to long. That is what I mean. An ! (exclamation) means parameter1 is not equal to long, when in fact it is.

When I used an ! , the condition is met.
When I leave out an !, the condition is never met.

Please explain. An ! means it should not equal, when in this case it is.
 
Old 08-14-2003, 12:46 PM   #4
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
as the man page states, strcmp returns 0 if the strings are equal, non-zero otherwise. so !strcmp returns 0 if there not equal, and non-zero if they are equal.
 
  


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
Print-to-file print driver to print PDF Bill Fox Linux - General 3 05-02-2006 04:15 PM
How to get next executed line phuna Programming 2 07-08-2005 12:05 AM
.bashrc not being executed, why? realos Linux - Newbie 1 12-20-2003 07:46 PM
.bash_logout does not get executed nearfar Linux - Newbie 3 10-17-2003 11:40 AM
.xinitrc isn't executed hampel Linux - Software 5 08-06-2003 03:53 AM

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

All times are GMT -5. The time now is 03:36 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