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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-13-2003, 05:55 PM
|
#1
|
Member
Registered: Apr 2003
Posts: 178
Rep:
|
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);
}
|
|
|
08-13-2003, 06:14 PM
|
#2
|
Senior Member
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263
Rep:
|
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
|
|
|
08-14-2003, 12:28 PM
|
#3
|
Member
Registered: Apr 2003
Posts: 178
Original Poster
Rep:
|
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.
|
|
|
08-14-2003, 12:46 PM
|
#4
|
Senior Member
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263
Rep:
|
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:14 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|