hello all
I'm trying to do a concatenation function I do not want to you use the strings property where we can add strings, I need to add two strings and save them in one string without the use of addition "+"
i have three variables title , first_name, last_name I should somehow combine them and save the result inside the full_name string and return it and then print it from the main function. so all the three varaibles should be saved inside one variable which is full name.
what I did here is a void function coz I was not sure how will I do it otherwise ..
there's some other issue which is that the first character of the full_name is ommited and there's no space between first name and last name
here's the code .. your guidence is highly appreciated
# include <iostream>
# include <string>
using namespace std;
void concat( char [], char [], char [], string , int, int, int);
int string_length( char []);
int main()
{
// l for the lengths
int l1, l2, l3;
char title[]="Dr";
char first_name[]="Christina";
char last_name []="Brown";
string full_name;
l1 =string_length(title);
l2 =string_length(first_name);
l3 =string_length(last_name);
concat( first_name, last_name, title,
full_name, l1, l2, l3);
}
int string_length( char anything[])
{
int length=0;
for (int i=0; anything[i]!='\0'; i++)
{
length++;
}
return length;
}
void concat( char first_name[], char last_name[],
char title[], string full_name,
int l1, int l2, int l3)
{
for(int i=0; i<l1; i++)
{
full_name = title[i];
}
for(int i=0; i<l2; i++)
{
full_name = full_name + first_name[i];
}
for(int i=0; i<l3; i++)
{
full_name = full_name + last_name[i];
}
cout << full_name;
cout <<endl;
cout <<endl;
}