LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Print statement never executed (https://www.linuxquestions.org/questions/programming-9/print-statement-never-executed-81736/)

Linh 08-13-2003 05:55 PM

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);
 }


kev82 08-13-2003 06:14 PM

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

Linh 08-14-2003 12:28 PM

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.

kev82 08-14-2003 12:46 PM

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.


All times are GMT -5. The time now is 12:03 PM.