Char Pointer Argument/Parameter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Copeland

    Char Pointer Argument/Parameter

    How do I distinguish a pointer to a character variable versus a
    pointer to a C-type character string? For example,

    void Funct1(char *str) // "str" is a character string variable
    void Funct2(char *chr) // "chr" is a single character variable

    In both cases, I wish to modify the parameter argument, but it seems
    to me they are really different data types.
    Also, is there any way to _override_ the declaration of a function
    with these 2 distinctive data types? Please advise. TIA
  • Jim Langston

    #2
    Re: Char Pointer Argument/Parameter

    "Mike Copeland" <mrc2323@cox.ne twrote in message
    news:MPG.22e2d2 a488a6ff4198970 c@news.cox.net. ..
    How do I distinguish a pointer to a character variable versus a
    pointer to a C-type character string? For example,
    >
    void Funct1(char *str) // "str" is a character string variable
    void Funct2(char *chr) // "chr" is a single character variable
    >
    In both cases, I wish to modify the parameter argument, but it seems
    to me they are really different data types.
    Also, is there any way to _override_ the declaration of a function
    with these 2 distinctive data types? Please advise. TIA
    They actually aren't different types that is. A pointer doesn't care if it
    points to one object, or a number of objects. One thing you could do for
    yourself to help self document it a little is:

    void Func1( char str[] ) // "str" is a character string variable
    void Func2( char* chr ) // "chr" is a single character variable

    But it really doesn't make a difference. Although I've never seen the []
    format used for a single character. You can still pass the address of a
    single character to Func1 or Func2, or an array.


    Comment

    • Daniel T.

      #3
      Re: Char Pointer Argument/Parameter

      mrc2323@cox.net (Mike Copeland) wrote:
      How do I distinguish a pointer to a character variable versus a
      pointer to a C-type character string? For example,
      >
      void Funct1(char *str) // "str" is a character string variable
      void Funct2(char *chr) // "chr" is a single character variable
      >
      In both cases, I wish to modify the parameter argument, but it seems
      to me they are really different data types.
      Also, is there any way to _override_ the declaration of a function
      with these 2 distinctive data types? Please advise. TIA
      Use this for Funct2:

      void Funct2(char& chr);

      Comment

      Working...