This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

about memcpy and strcat?

Sorry i haven't read the notes before. So i am sending it again.When I debugging my program, the following function is not working proper. Actually this function runs properly on C, but not in Keil. There are 2 different problems occured.

1) strcat cannot add 2 strings. after strcat no any results.

2) once i merge this function into main function, the second memmmove is also working inproper.
The pointer of T and CngStr are becoming the same.
How can I solve it?

void main()
{
      SerialInit();
      printf("After Function %s\n",Change("0912cf4f3c"));
return;
}
char *Change(char *Str){
      char *CngStr;
      char *T;
      char *Change(char *Str){
      char *CngStr;
      char *T;
      CngStr = (char *) malloc (strlen(Str)+2);
       T = (char *) malloc (strlen(Str));
       strcpy(CngStr,"");
       strcpy(T,"");
       memmove(CngStr,Str+2,8);
       CngStr[8] ='\0';
       memmove(T,Str,2);
       T[2] ='\0';
       strcat(CngStr,T);
       free(T);
       return(CngStr);
}

0