Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!elroy.jpl.nasa.gov!ames!haven!umd5!jupiter.astro.umd.edu!jjk From: jjk@jupiter.astro.umd.edu (Jim Klavetter) Newsgroups: comp.lang.c Subject: confusion with char *a and char a[NUM] Message-ID: <7656@umd5.umd.edu> Date: 3 Dec 90 07:38:58 GMT Sender: news@umd5.umd.edu Reply-To: jjk@astro.umd.edu( Jim Klavetter) Distribution: na Organization: U of Md., Astronomy Program Lines: 40 I am not a beginner and I have checked my texts, man pages, and the faq list (Thanks Steve, I think it is a good job). I am still confused. I think part of the problem is with an inconsistency in c and part is my understanding. I can have two identical files except that one I declare a to be char a[NUM] and the other has char *a with a malloc of NUM+1 characters. I guess I can stop there and ask the general question, "what is the difference between those two?" If done properly, they will both be NUM+1 bytes (or whatever a char is) of memory and should be accessible either by a[3] or *(a+3) for the forth element, for example. Yet, there are differences. In both cases, the following is accepted by both my sun4 compiler and gcc strcpy(string, a) and there is no problem. However, if I have a=strchr(string, ":"); I get the error message 121: incompatible types in assignment or some such thing (that one is from gcc). The man page treats both the arguement of strcpy() and the return value of strchr() as type (char *). So why this inconsistency? Am I using strcpy() wrong above and just getting away with a flaw in the compiler, or is there actually an inconsistency here. Thanks in advance. jjk@astro.umd.edu Jim Klavetter (accepting mail for Athabasca and Reudi) Astronomy UMD College Park, MD 20742 Brought to you by Super Global Mega Corp .com