I've been trying for hours and still haven't been able to figure out whats the problem. I've tried many variations in the functions, but still unsure. I'm trying to make a program that changes the inputted array of names first name middle name, and last name to different format (Last Name, First Name Middle Inital). While capitalizing the first letters and making the middle name an inital. I'm trying to get the first, middle, and last names into one array first which are seperated by spaces, then copying them into different arrays, character by character using a for loop. Then deleting the name copied in the main array by just moving the arrays back to array 0 from the first space. I'm thinking there might be problems with the two functions I made to send the names to the other arrays and the array moving back portion. Please bare with my coding, still a beginner... anyone have any advice on what might be the problem?
#include <cctype>
#include <cstring>
#include <iostream>
using namespace std;
void sort_name(char name[], char new_name[]);
void remove_name(char name[], int space);
const int NUM_LETTERS = 21;
const int MAX_LETTERS = 64;
int main()
{
char get_name[MAX_LETTERS], last_name[NUM_LETTERS], first_name[NUM_LETTERS],
middle_inital[NUM_LETTERS];
cout << "\nPlease enter your first name, middle initial, and last name.\n"
<< "(max 20 letters per name)\n";
cin >> get_name;
sort_name(get_name, first_name);
sort_name(get_name, middle_inital);
sort_name(get_name, last_name);
cout << last_name << ", " << first_name << " " << middle_inital << "." << endl;
return 0;
}
void remove_name(char name[], int space)
{
int size = NUM_LETTERS;
// space++;
for(int i = space; i < space; i--)
name[i] = name[i+1];
}
void sort_name(char name[], char new_name[])
{
for(int i=0; i<MAX_LETTERS; i++)
{
if(!isspace(name[i]))
{
remove_name(name, i);
break;
}
else
new_name[i] = name[i];
}
new_name[0] = static_cast<char>(toupper(new_name[0]));
}