strcat/access question

Jim Klavetter jjk at astro.UMD.EDU
Tue Oct 3 07:59:36 AEST 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.  I've included the appropriate
files.  Any response to the above address would be appreciated (and
I will summarize the response if there is some good answer(s)).

jjk



More information about the Comp.lang.c mailing list