Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!ames!ucsd!mvb.saic.com!ncr-sd!iss-rb!tortuga!ewing From: ewing@tortuga.SanDiego.NCR.COM (David Ewing) Newsgroups: comp.sys.amiga.programmer Subject: Re: Compairing C values Message-ID: <1991Feb6.211923.2940@SanDiego.NCR.COM> Date: 6 Feb 91 21:19:23 GMT References: <606.27aede55@vger.nsu.edu> Sender: @SanDiego.NCR.COM Reply-To: ewing@tortuga.SanDiego.NCR.COM (David Ewing) Organization: NCR Corporation, Rancho Bernardo Lines: 56 Newsgroups: comp.sys.amiga.programmer Subject: Re: Compairing C values Summary: also assigning a char * to a char References: <606.27aede55@vger.nsu.edu> Reply-To: ewing@tortuga.SanDiego.NCR.COM (David Ewing) Distribution: na Organization: NCR Corporation, Rancho Bernardo >> void main(int argc, char *argv[]) >> { >> char a = argv[1]; >> if (a = '+') printf("a equals +"); ... In addition to the use of the wrong operator as already mentioned (ie, you used = instead of ==), you are assigning a char pointer to a char : char a = argv[1]; argv is an array of char pointers, therefore argv[1] is a char pointer, not a char. This should either be : char a = *argv[1]; /* note : dereferencing the pointer */ if (a == '+') { /* do whatever */ } if you are only concerned with the first character in the second string (ie, this will accept "test +anything" as well as just "test +") -- or if you only want to accept "+" and not "+anything" : char *a = argv[1]; /* note a is now a char * */ if (a) { /* be sure argv[1] was not NULL !!! */ if (strcmp(a, "+") == 0) { /* do whatever */ } } David Ewing ewing@se-sd.sandiego.ncr.com Newsgroups: comp.sys.amiga.programmer Subject: Re: Compairing C values Summary: Expires: References: <606.27aede55@vger.nsu.edu> Sender: Reply-To: ewing@tortuga.SanDiego.NCR.COM (David Ewing) Followup-To: Distribution: Organization: NCR Corporation, Rancho Bernardo Keywords: ********************************************* David A. Ewing ewing@tortuga.sandiego.ncr.com *********************************************