hi and thanks for your rsponces ,but im stock again at the nd of my progrand, waht i need to do is concanate first 2 characters of one string to another, it does it fine but i get a whole bunch of other character at the end of it plus the same string again, how do i stop that from happening here is some of my code, i have included <cstring>
Code:
int main()
{
char string1[10];
char string2[15];
char string3[15];
char string4[8];
cout <<"Enter string1: ";
cin.getline(string1, 10, '\n');
cout <<"Enter string2: ";
cin.getline(string2, 15, '\n');
cout<<endl<<string1<<" is "<<strlen(string1)<<" characters in length"<<endl;
cout<<string2<<" is "<<strlen(string2)<<" characters in length"<<endl;
cout<<endl<<string1<<" is "<< sizeof(string1) << " characters in size"<<endl;
cout<<string2<<" is "<< sizeof(string2) << " characters in size"<<endl;
if (strcmp(string1,string2) !=1 || 0)
{
cout<<endl<<string1<<" is less than "<<string2<<endl;
}
cout<<endl<< "string3 after concatenation is "<<strcat(string1,string2)<<endl;
cout<<endl<<"String 4 is " <<strncpy(string2,string1,3)<<endl;
cout<<endl<<"String 1 is now " <<strncpy(string2, string1,7)<<endl;
return 0;
}
im entering billy for string 1
bob for string 2