Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!ames!uhccux!munnari.oz.au!yoyo.aarnet.edu.au!sirius.ucs.adelaide.edu.au!adam.adelaide.edu.au!phil From: phil@adam.adelaide.edu.au (Phil Kernick) Newsgroups: comp.sys.amiga.misc Subject: Re: Compairing C values Message-ID: Date: 7 Feb 91 23:06:50 GMT References: Sender: mrp@ucs.adelaide.edu.au Organization: University of Adelaide, South Australia Lines: 51 Nntp-Posting-Host: adam.adelaide.edu.au rat@hotcity.UUCP (P W) writes: > I have + as an input arguement via *argv[] and whenever I try to >compare its value it comes out as a 0. For instance... If I compile a >program like this: >#include >#include >void main(int argc, char *argv[]) >{ > And I type "test +" (I would name the file test) it would just print a >equals 0. Any help would be appereciated... >char a = argv[1]; >if (a = '+') printf("a equals +"); >if (a = '0') printf("a equals '0'"); >if (a = 0) printf("a equals 0"); >} Lots of things wrong here. 1. This program will not even compile because char a = argv[1]; is not a valid declaritor. 2. You should check that argv[1] is valid by making sure that (argc > 1). Otherwise (argv[1] == 0) and you do *not* want to dereference that. 3. argv[1] is a pointer to a pointer to a char, what you want is: char a; a = *argv[1]; 4. The if (a = ...) statement is an assignment, not a comparison. You need statements like: if (a == '+') printf("a equals +"); 5. All of the above asside, you *cannot* have a lone '+' as a parameter to a program, because AmigaDos eats it. See the documentation for the RUN command. Phil. -- o| /// Phil Kernick EMail: phil@adam.adelaide.edu.au |o | /// Departmental Engineer Phone: +618 228 5914 | o| \\\/// Dept. of Psychology Fax: +618 224 0464 |o | \/// University of Adelaide Mail: GPO Box 498 Adelaide SA 5001 |