Originally posted by pode
hi all,
how do u copy a string to another string whithout using
strcpy()
sure if its possible use strcpy() but all i get is errors
i'm using 2 for loops like this
char temp[10];
for(cin>>ansver;ansver!='q';cin>>ansver)
for(int c=0;c<strlen(string);c++) //string is 10 slots
{
if(pointer[c]==answer) // pointer points to string
{
strcpy( temp[c], pointer[c]) // i thought something like this must
do the job. but i get errors
}} i know why i get errors but i dont know any other way to do this except memcpy() but that would'nt do
the job
That doesn't make sense to me. Try this instead:
Code:
char String1[32] = "Hello world!";
char String2[32] = "";
strcpy(String2, String1);
cout << String2;
And if you're not allowed to use strcpy, make your own:
Code:
void strcpy(char* Buffer, char* String)
{
int Pos = 0;
while(String[Pos] != '\0')
{
Buffer[Pos] = String[Pos];
Pos++;
}
Buffer[Pos] = '\0';
}