Mail Archives: djgpp/1999/12/10/03:40:03
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 -