copy string ..

Mar 10, 2013 at 9:21pm
Hello ..
I want to copy the string from orig to dest. by the function ypcrts.. so what is the problem in my code.. thx a lot


#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <stdio.h>
#include<string.h>
using namespace std;

char ypcrts(char* dest, char *orig)
{
char c;
char *p;
int i=0;
for (p = orig + strlen(orig)-1 ; dest < orig; dest+i, p--)
{
i++;

c = *orig;

*dest = *p;

*p = c;
}
return *dest;
}
int main()
{

char *ch1;
ypcrts(ch1, "Hello");

printf("%s", ch1);

return 0;
}
Mar 10, 2013 at 9:23pm
so I want to get .... ch1=olleH
Mar 10, 2013 at 9:25pm
Mar 10, 2013 at 9:31pm
@ ne555..

I'm beginner... is there sth not clear in my code ...???
Mar 10, 2013 at 10:54pm
You are not doing what you think you are doing.
So comment your code with the intention (please use code tags)
Topic archived. No new replies allowed.