#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void mem_move_foo(void *dest, void *src, int total_bytes)
{
int i = 0;
char *lSrcStr=(char *) src;
char *lDestStr=(char *) dest;
char *lTempStr;
lTempStr= malloc(total_bytes*sizeof(char*));
for(i=0 ;i < total_bytes ; i++)
{
lTempStr[i] = lSrcStr[i];
}
for(i=0;i<total_bytes;i++)
{
lDestStr[i]=lTempStr[i];
}
free(lTempStr);
}
int main()
{
char srcStr[]="HelloSrc";
printf("String before :: [%s]\n",srcStr );
mem_move_foo(srcStr+5,srcStr,strlen(srcStr)+1);
printf("String after :: [%s]\n",srcStr );
return 0;
}
#include<string.h>
#include<stdlib.h>
void mem_move_foo(void *dest, void *src, int total_bytes)
{
int i = 0;
char *lSrcStr=(char *) src;
char *lDestStr=(char *) dest;
char *lTempStr;
lTempStr= malloc(total_bytes*sizeof(char*));
for(i=0 ;i < total_bytes ; i++)
{
lTempStr[i] = lSrcStr[i];
}
for(i=0;i<total_bytes;i++)
{
lDestStr[i]=lTempStr[i];
}
free(lTempStr);
}
int main()
{
char srcStr[]="HelloSrc";
printf("String before :: [%s]\n",srcStr );
mem_move_foo(srcStr+5,srcStr,strlen(srcStr)+1);
printf("String after :: [%s]\n",srcStr );
return 0;
}
No comments:
Post a Comment