Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!fluke!ssc-vax!coy From: coy@ssc-vax.UUCP (Stephen B Coy) Newsgroups: comp.sys.ibm.pc Subject: Re: why does this compare fail in TC2.0? Message-ID: <2868@ssc-vax.UUCP> Date: 29 Aug 89 20:06:07 GMT References: <127@cica.cica.indiana.edu> Distribution: na Organization: Boeing Aerospace Corp., Seattle WA Lines: 27 Keywords: C question about compares in turbo c 2.0 In article <127@cica.cica.indiana.edu>, burleigh@cica.cica.indiana.edu (Frank Burleigh) writes: > this is driving me fairly crazy. i'm using turbo c 2.0. > > if( fld == ".," ) > ptr_tmp[i] = strtod( "+NAN", NULL ); /*missing value*/ Remember, fld is a pointer. ".," is also a pointer. What you are comparing here are two pointer values. Since fld points to part of your input string and ".," points to the constant string ., in memory they will never be equal. What you want in this case is to compare the first two characters pointed to by the pointers. if(strncmp(fld, ".,", 2) == 0) /* if equal */ ... > if( fld[0] == '.' && fld[1] == ',' ) ... > which works correctly. Yes, it should. In this case you are comparing chars which is what you want. > Frank Burleigh burleigh@cica.cica.indiana.edu > USENET: ...rutgers!iuvax!cica!burleigh BITNET: BURLEIGH@IUBACS.BITNET > Department of Sociology, Indiana University, Bloomington, Indiana 47405 Stephen Coy uw-beaver!ssc-vax!coy