From owner-freebsd-questions Tue Nov 6 22: 0:45 2001 Delivered-To: freebsd-questions@freebsd.org Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by hub.freebsd.org (Postfix) with ESMTP id 72F7B37B418 for ; Tue, 6 Nov 2001 22:00:41 -0800 (PST) Received: (from dan@localhost) by dan.emsphone.com (8.11.6/8.11.6) id fA760XR82215; Wed, 7 Nov 2001 00:00:33 -0600 (CST) (envelope-from dan) Date: Wed, 7 Nov 2001 00:00:33 -0600 From: Dan Nelson To: Matthew Blacklow Cc: questions@FreeBSD.ORG Subject: Re: Changing the value of a constant Message-ID: <20011107060033.GA67329@dan.emsphone.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.23.1i X-OS: FreeBSD 5.0-CURRENT X-message-flag: Outlook Error Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In the last episode (Nov 07), Matthew Blacklow said: > I am writing a C program under FreeBSD and am required to open a file > for reading. I have no trouble opening files when the address is hard > coded. However the fopen function requires that the path be a const > char. My problem is that the everytime the program runs it need to > open a different file and that is determined sometime during the > programs execution. I need to know how to modify the value of a > constant under C. The 'const' attribute in function prototypes refers to the function's behaviour: it promises not to modify the data you pass to it. For example, take a look at the prototype to strcpy: char *strcpy(char *dst, const char *src); It promises not to modify the string pointed to by src, but does not promise that dst will be the same value it was before it was called (it would not be a very good strcpy routine if it was :) Your code is free to modify its own string pointers between calls to fopen(). -- Dan Nelson dnelson@allantgroup.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message