0

Hey guys, I need help with this one. I'm writing a really basic program that will generate a character array firstName[amount][size]. using this it will then pass it to the function addPerson and that will modify the value.

Here's my current code

void deletePerson(int &, int, char[], char[], char[], char[]);
int main()
{
char firstNames[100][25], lastNames[100][25], email[100][50], phone[100][16];
else if (userChoice == 'D')
    {
        deletePerson(count, amount, &firstNames,&lastNames,&email,&phone);
    }
}
void deletePerson(int count, int amount, firstNames&, lastNames&,email&,phone&);
{
//blahblahblah
}

I know that it's wrong and pardon my newbieness. I had it working to a point where it only had on error but then i decided to change everything. Anyway, I hope you get the point of what i'm trying to say. Basically i Need to pass the array and have it modified inside the function. How might i go about that?

Thanks!

edit: Ok so i can't use global variables either, that'd be too easy.

I edited the code to get rid of the &. it gives me

error LNK2019: unresolved external symbol "void __cdecl deletePerson(int &,int,char (* const)[25],char (* const)[25],char (* const)[50],char (* const)[16])" (?deletePerson@@YAXAAHHQAY0BJ@D1QAY0DC@DQAY0BA@D@Z) referenced in function _main

my new code looks like

void deletePerson(int &, int, char[][25], char[][25], char[][50], char[][16]);
int main()
{
char firstNames[100][25], lastNames[100][25], email[100][50], phone[100][16];
else if (userChoice == 'D')
        {
            deletePerson(count, amount, firstNames,lastNames,email,phone);
        }
}
void deletePerson(int count, int amount, char firstNames[100][25], char lastNames[100][25],char email[100][50],char phone[100][16])
{
    int position; //the place where the person is in the array
    position = searchName(count, amount, lastNames);
    if (position != -1)
    {
    }

}

1
  • Your second code block declares and uses void deletePerson(int &, int, char[][25], char[][25], char[][50], char[][16]), but does not define it. It does define a completely unrelated(!) function with signature void deletePerson(int, int, char[100][25], char[100][25],char[100][50],char[100][16]), which is unused. Make sure to use exactly the same signature for declaration and definition. Commented Nov 29, 2010 at 8:13

2 Answers 2

2

I think you should really avoid using char arrays and char pointers. Use std::vector and std::string instead, they will save you a lot of trouble. std::vector<std::string> is probably all you need. Or even better, you should bundle firstName, lastName, email and phone together in a structure.

struct Person
{
    std::string firstName;
    std::string lastName;
    std::string email;
    std::string phone;
}

void deletePerson(std::vector<Person>& persons)
{
    int position = searchName(lastNames); // you could replace this with std::find
    if (position != -1)
    {
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

I would, but I can't as this is a requirement. So any idea on making this work? I'm running out of ideas
0

Try this:

It uses the template argument deduction and references to simplify things. It works in case you change the dimensions of your arrays for whatever reason without changing the function (and possibly the logic).

template<class T, int N1, int N2, int N3, int N4, int N5, int N6, int N7, int N8>
void deletePerson(int &, int, T(&r1)[N1][N2], T(&r2)[N3][N4], T(&r3)[N5][N6], T(&r4)[N7][N8]){} 

int main() 
{ 
   char firstNames[100][25], lastNames[100][25], email[100][50], phone[100][16]; 
   int count = 100;
   deletePerson(count, 20, firstNames, lastNames, email, phone); 
} 

1 Comment

Thanks! I decided to do the code a different way. Thank you for helping though!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.