I am trying to write a really simple program, but here I can not find the problem. Tried different methods, here is what I tried now:
#include <stdio.h>
void copyStr(char *p, char *h){
int i=0,j=0;
int length=0;
length=strlen(p); int l=length;
for (i=0; i<length; i++){
h[i]=p[l-1];
l--;
}
char *temp=&h[0];
for (i=0; i<length; i++){
printf("%c",temp[i]);
}
}
main(){
char p[]="abcde";
char h [sizeof(p)];
copyStr(p,h);
}
When I copy these lines, the first letter does not seem to be copied.
My purpose is actually more, trying to copy the lines in REVERSE, but I believe that figuring out what went wrong will help me succeed.
Any help is assigned.
EDIT: enabled, code now works.
source
share