I want to assign a char* to char* , if I use strcpy I get several run time memory problem so I fix it by simple assignment using = operator.
Can any one explain what should prepare before using strcpy to avoid memory issues.
EDIT:
int Function(const char* K,char* FileIN,char* FileOut,int DC)
{
char *fic_in,*n_fic,*fic_out,*fic_dec;
unsigned char k[17];
fic_in = (char*)malloc(60*sizeof(char));
strcpy((char*)k,K);
//strcpy(fic_in,FileIN); //I remove this one
fic_in=FileIN; //and replace it by this
...
ais a pointer that points to a string literal.bis a pointer that doesn’t point anywhere in particular (it is uninitialized).bnow points to the same memory thatapoints to.cis now an array of 100 chars. That area of memory is completely separate from everything else so far.The contents of
c(to be specific, the first 15 bytes) now hold the same values as the memory pointed to bya. So now there are two regions of memory that contain the same string data.So as you can see, assigning pointers has pretty much nothing in common with
strcpy. If you want to assign achar*to achar*, then you shouldn’t be anywhere nearstrcpy.It’s essential that you read a book about C++, but the basic requirement for
strcpyis that the destination pointer must point to a region of memory with enough space for the string that the source pointer points to. Probably your “run time memory problems” were because you didn’t ensure that, which is why you need to read a book.