Hello : ) I have a problem with my C++ program. I don't know how to print first and the last name in reverse order using pointers. For example if user type: "First Last" program should output: "Last, First" (with comma). I can't change a main program, use vectors or change function prototype. I also have to use dinamic allocation memory. Thank you for any help!
#include <iostream>
#include <iomanip>
usingnamespace std;
char *LastFirstName(char *name);
int main()
{
char fullname[41], *ptr;
// Force user to enter full name, if not entered, ask again
while (true)
{
fullname[0] = '\0';
cout << "Enter your full name: ";
cin.getline(fullname, 40);
if (fullname[0] == '\0')
cout << "Name not entered. Re-enter full name.\n";
elsebreak;
}
cout << "Before calling function LastFirstName(), name is " << fullname << endl;
ptr = LastFirstName(fullname);
cout << "After calling function LastFirstName(), name is " << ptr << endl;
system("pause");
return 0;
}
//
char *LastFirstName(char* name)
{
int i = 41;
char* ptr = newchar(41);
// ???
for (i; i < 0;i--)
{
*name = ptr[i];
}
return ptr;
}