Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Jul 1998 19:37:11 -0400 (EDT)
From:      David Kott <dakott@alpha.delta.edu>
To:        shanzhong@163.net
Subject:   Re: your mail
Message-ID:  <Pine.BSF.3.96.980713190106.26626A-100000@kott.my.domain>
In-Reply-To: <19980713061431.20191.fmail@163.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On 13 Jul 1998 shanzhong@163.net wrote:

> Hello:
>    I use c for freebsd(unix) to program the cgi code ,
> but if i want to open a file 
> name=".//dirname//name.html";
> fopen(name,"r");
> always generate the error.
> can you help me?
> 
> 
> ________________________________________________
> ;6S-DzJ9SC9cV]JS40Cb7Q5gWSSJOdhttp://www.163.net
> 

Are you attempting to escape the "/" character?  Like "\/usr\/home\/foo"?
I don't think you need to do that.  Also, you can't "equate" a pointer to
an array to a string (presuming that "name" is an array).  You must do a
memberwise copy.  I suggest strcpy().

#include <stdio.h> 
#include <string.h> 
void 
main(void)  {

        FILE *fp; 
        char chaArray[45] = {'\0'}; 
        char chaTestString[80]; 

        strcpy(chaArray, "./test.c");  // your name="/usr/home/foo";
        printf("chaArray = \"%s\"\n", chaArray);  // Yes, I'm really here.
        fp = fopen((const char *) chaArray, "r");  // Hi, I will be your
                                                   // file pointer today.
        do {
                (void) fgets(chaTestString, 79, fp); 
                // cat /dev/codingflames > /dev/null | tee /dev/:-)
                printf("bytes read from %s:%s",
                       chaArray,
                       chaTestString); 
        } while (!feof(fp)); 
        fclose(fp);  
}

								-d



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.96.980713190106.26626A-100000>