Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!ux1.cso.uiuc.edu!uxc.cso.uiuc.edu!uxc.cso.uiuc.edu!m.cs.uiuc.edu!s.cs.uiuc.edu!mccaugh From: mccaugh@s.cs.uiuc.edu Newsgroups: comp.lang.c Subject: Re: strcat/access question Message-ID: <207600049@s.cs.uiuc.edu> Date: 4 Oct 89 07:13:00 GMT References: <5409@umd5.umd.edu> Lines: 29 Nf-ID: #R:umd5.umd.edu:5409:s.cs.uiuc.edu:207600049:000:1037 Nf-From: s.cs.uiuc.edu!mccaugh Oct 4 02:13:00 1989 > Here is a section of code: > > if((home=getenv("HOME"))==(char *) 0) > perror("GETENV\n"); > printf("%s:\n", home); > printf("%s:\n", strcpy(string,strcat(home, "/astro/data/obs.list"))); > printf("%s:\n", string); > printf("%d:\n", access(string, 4)); > printf("%d:\n", access(strcat(home, "/astro/data/obs.list"), 4)); > > And the associated output: > > /a/jjk: > /a/jjk/astro/data/obs.list: > /a/jjk/astro/data/obs.list: > 0: > -1: > > The man page says that strcat returns a null-terminated string so that > the two calls to access (I think) should both give "0" but the second > is saying the file doesn't exist. Actually, I recall the 'man' page stating that strcat returns a pointer (char-type) to the null-terminated string, but in any case I suspect that the last printf contains a call to strcat which assigns to your string-variable 'home' the name of a truly non-existent file, namely: "/a/jjk/astro/data/obs.list/astro/data/obs.list", so a redundant 'strcat' appears to have occurred in variable 'home'.