home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!mcrware!adam
- From: adam@microware.com (Adam Goldberg)
- Subject: Re: sscanf? What am I doing wrong?
- Message-ID: <1992Sep3.134259.14601@microware.com>
- Sender: news@microware.com
- Nntp-Posting-Host: ren
- Organization: Microware Systems Corp., Des Moines, Iowa
- References: <1992Aug31.154655.15737@magnus.acs.ohio-state.edu>
- Date: Thu, 3 Sep 1992 13:42:59 GMT
- Lines: 39
-
- kpearce@magnus.acs.ohio-state.edu (BULLDAWG) writes:
-
- >char partA[20]; \* and is for example "transmit data" *\
- >char tran[] = "transmit"
-
- > if (partA==tran)
- > {
- > printf("We have a match\n");
- > }
- > else
-
- >This always fails. I have tried putting \r\0 and various other control
- >characters at the end of the ttest string tran[] to no avail.
-
-
- partA and tran are both POINTERS to some number of characters. The
- if statement (partA == tran) is checking if the POINTERS are equal...
- clearly they're not, unless you did something previously like
- partA = tran.
-
- What you (probably) want to do is something like this:
-
- if(strcmp(partA, tran)==0)
- {
- match
- }
-
-
- or
-
- if(strncmp(partA, tran, strlen(partA))==0)
- { ... }
-
-
- --
- Adam G.
- adamg@microware.com, or ...!uunet!mcrware!adamg
- The above is not to be construed in any way as the official or unofficial
- statements of Microware, or any Microware employees.
-