C Pointer Help ....

Ben Duncan bend at linux4ms.net
Wed Sep 23 06:42:17 PDT 2009


Ok for the PAST few days, i have been refreshing myself back on C.

I was parsing thru a program that extends Python and got a compile error on
Character Buffer pointers. I fieed the error than pondered about it for a while,
and have become totally confused (O.F. syndrome ).

Ok, here is my Questions, I have a pointer to a char buffer defined as
char *Buffer ;

myfunction ( &Buffer ) ;

I want to pass it to a function change what it points to:

myfunction( Char *Buffer ) { ....

But C compiler complains :

warning: passing argument 1 of 'testpassptr' from incompatible pointer type

The goal is to have the function MODIFY what char *Buffer points to.

Can anyone tell me what I am doing wrong or missing ?

Thanks ...

++++++++++++++ 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 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 )
{

   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 ;


   return 0 ;
}



-- 
Ben Duncan - Business Network Solutions, Inc. 336 Elton Road  Jackson MS, 39212
"Never attribute to malice, that which can be adequately explained by stupidity"
        - Hanlon's Razor



More information about the Linux-users mailing list