delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/10/03:40:03

From: Nate Eldredge <neldredge AT hmc DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: changing value of pointers
Date: 10 Dec 1999 00:20:10 -0800
Organization: InterWorld Communications
Lines: 52
Message-ID: <83so1bb41x.fsf@mercury.st.hmc.edu>
References: <3850C822 DOT 1B33F13B AT dtn DOT ntl DOT com>
NNTP-Posting-Host: mercury.st.hmc.edu
X-Trace: nntp1.interworld.net 944814092 27092 134.173.45.219 (10 Dec 1999 08:21:32 GMT)
X-Complaints-To: usenet AT nntp1 DOT interworld DOT net
NNTP-Posting-Date: 10 Dec 1999 08:21:32 GMT
X-Newsreader: Gnus v5.7/Emacs 20.4
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Steven Watson <steven DOT watson AT dtn DOT ntl DOT com> writes:

> Hi Everyone
> 
> Is it possible someone can tell me how this code can be written to
> change the pointer sent to it
> in pow! using a VAR it will make a copy so the value can be changed but
> I am unable to figure it out in C?
> 
> int  main(void)
> char *string;
>   file_reads(1,5,&string);
>     printf("%s \n",string);
> return 0;
> }
> function from include file:
> 
> void file_reads(int handle,int length,char *dummy)
> {
> 
> 
>      if ((dummy=(char *)malloc(length+1))==NULL){
>         puts("Error code here");
>         exit(1);
>      }
> 
> 
> if((fread(dummy,sizeof(char),length,filehandle[handle]))!=length){
>             puts("Put error code here");
>             exit(1);
>          }
>                 *(dummy+length)=0x00;
>                printf("%s\n",dummy);//it prints here fine as expected.
> return;
> }


void file_reads(int handle, int length, char **dummy)
{
	if ((*dummy = (char *)malloc(length+1)) == NULL)
		/* handle error */
	if (fread(*dummy, blah, blah, blah) != length)
		/* handle error */
	*(*dummy + length) = 0;
}

This question might have been better asked in comp.lang.c, btw.
Actually, I think it's in their FAQ.
-- 

Nate Eldredge
neldredge AT hmc DOT edu

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019