Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!munnari.oz.au!cs.mu.oz.au!ok From: ok@cs.mu.oz.au (Richard O'Keefe) Newsgroups: comp.lang.c Subject: Re: strcat/access question Message-ID: <2280@munnari.oz.au> Date: 3 Oct 89 10:29:29 GMT References: <5409@umd5.umd.edu> Sender: news@cs.mu.oz.au Lines: 20 In article <5409@umd5.umd.edu>, jjk@astro.UMD.EDU (Jim Klavetter) writes: > if((home=getenv("HOME"))==(char *) 0) perror("GETENV\n"); > printf("%s:\n", home); At this point, home points to "/a/jjk\0" followed by who knows what > printf("%s:\n", strcpy(string,strcat(home, "/astro/data/obs.list"))); ^^^^^ At this point, home points to "/a/jjk/astro/data/obs.list\0" who knows what strcat() copies its second argument into the same array that its first argument points to, starting at the first NUL it finds there. > printf("%d:\n", access(strcat(home, "/astro/data/obs.list"), 4)); At this point, home points to "/a/jjk/astro/data/obs.list/astro/data/obs.list" > The man page says that strcat returns a null-terminated string so that Yes it does; and the pointer it returns is the pointer you gave it as its first argument. Sometimes it is simpler to forget strcat() and so on and just use sprintf: sprintf(work_string, "%s/astro/data/obs.list", home); This is unlikely to be a performance bottleneck.