Let's say I have a string (the current line in an array)
And the user want to insert a new string into a certain position of that string ... say... after the 5th character.
Can I use strncopy (CopyTo, CopyFrom, Numcells)
OR strncpy (Append To, AppendFrom, Numcells) ??
What is "Numcells" suppose to be, the position of where to insert the new string?
This is what I tried
Code:
......
cout <<"Where on the current line";
cout<<"do you want to insert a new string?"<<endl;
cin>> position;
cout<<"enter the string to be inserted: "<<endl;
cin.getline(temporary_array[0], 80, '\n');
strncpy (array[i-1],temporary_array[0],position);
cout<<"The current line is now: "<<array[i-1]<<endl;
.....
First of all, the whole program just exits as soon as it reaches "enter the string to be inserted"
But if I have this:
Code:
cout<<"enter the string to be inserted: "<<endl;
cin.getline(temporary_array[0], 80, '\n');
strncmp (array[i-1],temporary_array[0],6);
cout<<"The current line is now: "<<array[i-1]<<endl;
It just overwrites the first 5 characters of the original line.
I shouldnt be using strncpy() or what?