I have passed an array called originalname to the reverseWithPointers function below using a pointer and I have returned output from this function to the main program using a pointer. I would like to use pointers in other areas of this function but I don't know how or where to start.
Can someone explain or show me where else in the function I can use a point?
void reverseWithPointers(char *originalname, char *reversedname2)
{
int i,j; //declared two variables i & j
int k = -1; //set k to -1
char temps1[10]; //declare a temporary char array
char temps2[10]; //declare a temporary char array
//-------------------------------------------------------------------------------------------------
//This while loop reads up to the end of the first names...
while(originalname[k] != ' ')
{
k++; //increment k
temps1[k] = originalname[k]; //firs temp array will equal the first names.
}
k++; //increment k
//---------------------------------------------------------------
temps1[k]='\0'; //make temps1[k] = '\0'
j=0; //set j to zero..
//This while loop reads in the last names...
while(originalname[k] != ' '&& originalname[k] != '\0')
{
reversedname2[j] = originalname[k]; //set copy the last names into the reversedname2[j] array
k++;j++; //increment k and j
}
reversedname2[j]=',' ; //set reversedname2[j] to a comma
j++; //increment j outside the loop
reversedname2[j]=' ' ; //set reversedname2[j] to a space
k = -1; // set to k to -1 to read values starting before zero in the array.
//This array willl read in the first names
while(originalname[k] != ' ')
{
k++, j++; //increment j and k
reversedname2[j] = originalname[k]; //set the reversedname2[j] array to the originalname[k] array.
}
reversedname2[j]='\0';
//cout << temps2 <<" "<< temps1 << endl;
}
The purpose of the line 9 and line 29 is to grab the first name in each index of the array and store them in a temporary array called temps1 and temps2.
My issue is that I wanna use pointers in this array. I have already passed the originalname array as a parameter using a pointer. Now I would like to use pointers in other areas of this function?