CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2003
    Posts
    3

    passing char array

    Hello,
    Disclaimer: First time post. Lousy C programmer, but forced into a project.

    This seems simple but, within a function I declare a char array and then try to pass it, work on it , and then get it back:
    void InitialFunction()
    {
    char keyboard_input[20];
    //do some wori and then...
    keyboard_input = ReadTheKeyboard(keyboard_input);
    }


    and within the second function I do this:

    char ReadTheKeyboard(char keyboard_input[20])
    {
    //here i do my work and I can verify it is okay
    return(keyboard_input);
    }

    This causes compiler issues. So sorry to be a dolt, but how do I pass a char array, work on it, and get it back?

    Secondly, if I do this multiple times, how do I "empty" or "clear" the array "keyboard_input" before I use it again?

    Note: I use my own keyboard input routine and can verify that it works properly.

    Again, first time using this forum. I hope you can help. If I have done anything totally incorrect, I apologize.

    Thank you.
    Scott

  2. #2
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    2,236
    Code:
    void InitialFunction()
    {
    char keyboard_input[20];
    ReadTheKeyboard(keyboard_input,20);
    }
    
    void ReadTheKeyboard(char* keyboard_input,size_t size)
    {
    /// clear keyboard input
    memset( keyboard_input, 0, size );
    /// modify keyboard_input here
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured