C Pointer Help ....

Roger Oberholtzer roger at opq.se
Wed Sep 23 07:34:39 PDT 2009


On Wed, 2009-09-23 at 09:44 -0400, RIck bowers wrote:


Three changes. I put them in the code.

> > ++++++++++++++ Sample Program      ++++++++++++++++++++++++
> >
> > /*
> > **********************************************************************
> > A Cute Test Program for  FUNCTIOn Pointer testing
> > NOTE: Compile with
> >
> > gcc -o testptr testptr.c
> >
> > **********************************************************************
> > */
> > #include <unistd.h>
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <stdint.h>
> >
> > #include <ctype.h>
> > #include <string.h>
> >
> >
> > int testpassptr ( char *Buffer ) ;

int testpassptr ( char **Buffer ) ;

> >
> > int main ( int Argc, char **Argv )
> > {
> >
> >  int  Return_val = 0 ;
> >  char *Buffer = NULL ;
> >
> >  printf("We are at test point A \n" ) ;
> >
> >  Return_val = testpassptr( &Buffer ) ;
> >
> >  if (Return_val == 0 )
> >    {
> >      printf("we have process string: %s \n", Buffer ) ;
> >    }
> >  else
> >    {
> >      printf("what a FAILURE we are !!! \n " ) ;
> >    }
> >
> >  free(Buffer) ;
> >
> >  exit ( 0 );
> > }
> >
> >
> > int testpassptr (char *Buffer )

int testpassptr (char **Buffer )

> > {
> >
> >  char *Buf_ptr ;
> >
> >  if ((Buf_ptr = (char *) malloc(100)) == NULL)
> >     {
> >       printf("Memory allocation error! \n");
> >       return EXIT_FAILURE;
> >    }
> >
> >  printf("Memory allocated successfully! \n");
> >
> >  memset(Buf_ptr, '\0', 100 ) ;
> >
> >  strcpy(Buf_ptr, "A TEST String" ) ;
> >  printf("TESTPASSPTR string: %s \n", Buf_ptr ) ;
> >  Buffer = Buf_ptr ;

*Buffer = Buf_ptr ;

> >
> >
> >  return 0 ;
> > }

-- 
Roger Oberholtzer

OPQ Systems / Ramböll RST

Ramböll Sverige AB
Krukmakargatan 21
P.O. Box 17009
SE-104 62 Stockholm, Sweden

Office: Int +46 8-615 60 20
Mobile: Int +46 70-815 1696




More information about the Linux-users mailing list