Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!mephisto!rutgers!columbia!cubmol!ping From: ping@cubmol.bio.columbia.edu (Shiping Zhang) Newsgroups: comp.lang.c Subject: Re: Very elementary question concerning indirection Keywords: elementary question, indirection Message-ID: <1990Feb14.230034.3433@cubmol.bio.columbia.edu> Date: 14 Feb 90 23:00:34 GMT References: <7998@hubcap.clemson.edu> Reply-To: ping@cubmol.bio.columbia.edu (Shiping Zhang) Organization: Dept. of Biology, Columbia Univ., New York, NY Lines: 28 In article <7998@hubcap.clemson.edu> kaires@hubcap.clemson.edu (Robert G Kaires) writes: >I am just starting to learn C and I have what I'm sure is a very simple >question. Consider the following program fragment: >main() >{ > char *pointer; > char string[300]; > gets(string); > printf( "%c\n",*(strchr(string,40)) ); <---- line in question > pointer = strchr(string,40); > printf("%c\n",*pointer); >} By default, strchr() returns its value as an integer. So it is illegal to use it as a pointer. To solve this problem, just declare stachr() to be a function returning a pointer to char, as following: char *strchr(); By the way, it is not a good idea to use stachr() that way because it returns zero if it does not find the character, which will cause core dumping in this case. The returned value should be tested before it is used. -ping