pointer help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gemacjr1201
    New Member
    • Nov 2006
    • 14

    #1

    pointer help

    #include<iostre am>
    using namespace std;

    const int index=5;
    void getName(char,in t);

    int main()
    {



    char string[21];
    char *aString=string ;
    for(int count=0;count<i ndex;count++)
    {

    getName(aString ,index);
    cout << "you entered";
    cout << names;

    }
    return 0;
    }

    void getName (char names[][21], int index)
    {
    cout << "enter a name: ";
    cin >> names[index];
    }
    I need to enter a name 5 times
  • manontheedge
    New Member
    • Oct 2006
    • 175

    #2
    you've got a bunch of mistakes in your code. I would suggest trying to write the code without pointers, THEN worrying about the pointers after it works without them.

    one thing that's wrong are the variables you're passing, two of them aren't the right ones...the index of your array will always be set to [5], it should go up or down, and in the function definition, you're using a pointer not a 2-dimensional array, so it can't be passed like that. There's not that much to pointers once you figure out how they work, but knowing how to do other stuff is more important.

    Comment

    Working...