Path: utzoo!attcan!uunet!munnari.oz.au!murtoa.cs.mu.oz.au!ditmela!yarra!melba.bby.oz.au!leo!zvs From: zvs@bby.oz.au (Zev Sero) Newsgroups: comp.lang.c Subject: Re: Very elementary question concerning indirection Message-ID: Date: 15 Feb 90 06:41:03 GMT References: <7998@hubcap.clemson.edu> Sender: news@melba.bby.oz.au Organization: Burdett, Buckeridge and Young Ltd. Lines: 39 In-Reply-To: kaires@hubcap.clemson.edu's message of 14 Feb 90 16:41:31 GMT In article <7998@hubcap.clemson.edu> kaires@hubcap.clemson.edu (Robert G Kaires) writes: 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); } "partest.c", line 6: illegal indirection "partest.c", line 7: warning: illegal combination of pointer and integer, op = The first thing to do is to declare strchr as returning char *. #include The second point to consider is what happens if there is no '(' in the input line. In this case, strchr will return NULL, which will crash when you dereference it. What you might want to do is : pointer = strchr (string, '('); if (pointer) printf ("%c\n", *pointer); I presume you want to do more with it than that, or you could simply putchar ('('); Also, be aware that gets() is dangerous. If you give it more than 299 characters, it will crash. Use fgets (string, 299, stdin); string[strlen (string) - 1] = '\0'; This will get you up to 298 characters, without the '\n' at the end. -- Zev Sero - zvs@bby.oz.au Megalomaniacs are simply people who know damn well they can run the universe better then God or the present governors. - Abner Doon (Orson S. Card)