From owner-freebsd-questions Wed Jul 15 01:31:51 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id BAA13913 for freebsd-questions-outgoing; Wed, 15 Jul 1998 01:31:51 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from alpha.delta.edu (alpha.delta.edu [161.133.129.3]) by hub.freebsd.org (8.8.8/8.8.8) with SMTP id BAA13901 for ; Wed, 15 Jul 1998 01:31:49 -0700 (PDT) (envelope-from dakott@alpha.delta.edu) Received: from pm233-19.dialip.mich.net by alpha.delta.edu; (5.65v3.0/1.1.8.2/06Jan97-0932AM) id AA07858; Wed, 15 Jul 1998 04:35:08 -0400 Received: from kott.my.domain (dakott@kott.my.domain [192.168.0.1]) by kott.my.domain (8.8.8/8.8.5) with SMTP id TAA26939; Mon, 13 Jul 1998 19:37:11 -0400 (EDT) Date: Mon, 13 Jul 1998 19:37:11 -0400 (EDT) From: David Kott To: shanzhong@163.net Cc: Subject: Re: your mail In-Reply-To: <19980713061431.20191.fmail@163.net> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 #include 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