I am working on swapping each name in the array. Examples: Last name first, first name last. So the first name is Ben Dover, it should come out to Dover, Ben. etc etc....
I was able to get the first name and place it in a temporary array called temps1. I am having trouble getting the last names of each person and placing them in the temps1 array before the first name.
The code below will only print out the first name.
Can anyone show me my next step, or possibly help solve?
Out of interest, do you have any restrictions on what functions you can use? I can see you're using C++ strings for your data array, but nowhere else. And you're using strcpy but not, for example strchr?
Function 1:
Requires passing an array (originalname[100] ) to a function, then swapping the names, example: last name first, first name last, and then returning the reversed array in an array named (reversedname1[100]).
Functon 2:
Uses pointers, it requires passing the array (originalname[100]) to function 2 using pointers, and then returning the array using pointers with the names swapped also.
The hard part is getting the names swapped in the array inside both functions and returning the swapped names to the original program.
-----------------------
I have shortened the code above to to just work on the name swapping part.
-----------------------
Note: I am posting the original project below just in case anyone is wondering why I need the names swapped. No need to work it out, unless you want to. I will post the entire code when done.
This is the original project. It sucks, its tough, its missing alot of code, and it does not work. I am to use this program as a starting point, I am suppose to add the two missing functions, and submit the new complete program. The reverseWithArrays function must use [ ] notation, and the reverseWithPointers
function must use * notation.
The program requires using for loops to swap the names in the the array.
Below is what the code is suppose to output. The names in bold are the swapped names from the 2 functions created, one using array, and the other using pointers. This program should produce output similar to the following:
Ben Dover reversed with arrays is Dover, Ben
Ben Dover reversed with pointers is Dover, Ben
Chuck Roast reversed with arrays is Roast, Chuck
Chuck Roast reversed with pointers is Roast, Chuck
Jim Naysium reversed with arrays is Naysium, Jim
Jim Naysium reversed with pointers is Naysium, Jim
Ella Quint reversed with arrays is Quint, Ella
Ella Quint reversed with pointers is Quint, Ella
Justin Case reversed with arrays is Case, Justin
Justin Case reversed with pointers is Case, Justin