Arrays of Strings are fun
Okay, I have 2 functions I am trying to create. The first, will read in a character string array of numbers and insert dashes into it(like in a social security number or a phone number).
The second one will read in a string of characters in an array and cut-off one of the names by inserting the delimiter('\0')
However, I am having problems doing both. Any suggestions would be great.
Code:
void dashinsert(str x[])
{
for(int i=0;i<23;i++)
{for(int j=0;j<9;j++)
cout << x[j] << endl;
}
cout << x[4];
}
void cutoff(str x[])
{
//read-in array
//go through and insert '/0' after the first letter of middle name
}
Another suggestion - start small.
First, get the '\0' program working on your name without a loop, and without looking for the space.
Once that works, add the loop with the space-search.
For the hyphen, start by shifting the last character (no loop).
123456789 // Input
1234567899 // Output (shift last character)
Once, you have that working, make a loop to do this:
123456789 // Input
1234566789 // Output (shift last 4 characters)
Then:
123456789 // Input
12344566789 // Output
Finally, over-write the characters where the hyphens belong.
123456789 // Input
123-45-6789 // Output