I have a char array which contains some value . I want to copy the value from that array from some random index to some other random index . How can I do that ?
#include<iostream.h>
using namespace std;
int main()
{
char ar[100];
strcpy(ar,"string is strange");
cout << ar ;
return 0;
}
Now ar array contains “string is strange” . Suppose I want to make an another char array cp in which I want to copy the value from random index position of ar say from 7 to 10 . Is there some string function which we can use ?
I know we can use strncpy function but it copies from starting index till number of characters mentioned . Is there some other function or an overloaded version of strncpy
which will enable me to perform the same?
Do like this
generally
Therefore you need to null terminate the string manually:
UPDATE
You can use something like this:
When you are using C++, do not use the char strings for processing instead use the string class.