Memory Access STRCPY | developer.brewmp.com Memory Access STRCPY | developer.brewmp.com

Developer

Memory Access STRCPY

Forums:

I face Memory Access STRCPY error for the following code:
char* value = NULL;

pMe->mobile = (char*) MALLOC(STRLEN(value)+1);
pMe->mobile = STRCPY(pMe->mobile, value);

Rachel wrote:I face Memory Access STRCPY error for the following code:
char* value = NULL;
pMe->mobile = (char*) MALLOC(STRLEN(value)+1);
pMe->mobile = STRCPY(pMe->mobile, value);
What are you doing with the following statement
char* value = NULL;
pMe->mobile = (char*) MALLOC(STRLEN(value)+1);
Your variable(value) has a NULL value and u r doing a STRLEN of variable with no memory address.
Then STRCPY is copying from a source which has a NULL value...how is tat possible?
Assign some value to ur VALUE and then do the remaining steps. It will work then.

Rachel wrote:I face Memory Access STRCPY error for the following code:
char* value = NULL;
pMe->mobile = (char*) MALLOC(STRLEN(value)+1);
pMe->mobile = STRCPY(pMe->mobile, value);
What are you doing with the following statement
char* value = NULL;
pMe->mobile = (char*) MALLOC(STRLEN(value)+1);
Your variable(value) has a NULL value and u r doing a STRLEN of variable with no memory address.
Then STRCPY is copying from a source which has a NULL value...how is tat possible?
Assign some value to ur VALUE and then do the remaining steps. It will work then.

I still encounter the same problem even though I assign value to variable value as the following:
char* value = (char*)MALLOC(150);

I still encounter the same problem even though I assign value to variable value as the following:
char* value = (char*)MALLOC(150);

Rachel wrote:I still encounter the same problem even though I assign value to variable value as the following:
char* value = (char*)MALLOC(150);
i dunt understand what ur trying to do!!
if u want to try something with strcpy, then follow this
char * value = "test";
char * somebuffer = (char*) MALLOC (STRLEN(value)+1);
STRCPY(somebuffer,value);

Rachel wrote:I still encounter the same problem even though I assign value to variable value as the following:
char* value = (char*)MALLOC(150);
i dunt understand what ur trying to do!!
if u want to try something with strcpy, then follow this
char * value = "test";
char * somebuffer = (char*) MALLOC (STRLEN(value)+1);
STRCPY(somebuffer,value);

help please
i have problem on i thread start in MOTO W362.

help please
i have problem on i thread start in MOTO W362.

Rachel wrote:I still encounter the same problem even though I assign value to variable value as the following:
char* value = (char*)MALLOC(150);
What manju has written above is correct...assign the value(to ur variable VALUE) that you want to copy in ur pMe->Mobile.
Memory allocation would just assign a place to the variable in Memory....with STRLEN 0 would be returned.
That's why u r getting the problem.
Akshay

Rachel wrote:I still encounter the same problem even though I assign value to variable value as the following:
char* value = (char*)MALLOC(150);
What manju has written above is correct...assign the value(to ur variable VALUE) that you want to copy in ur pMe->Mobile.
Memory allocation would just assign a place to the variable in Memory....with STRLEN 0 would be returned.
That's why u r getting the problem.
Akshay

Rachel wrote:I face Memory Access STRCPY error for the following code:
char* value = NULL;
pMe->mobile = (char*) MALLOC(STRLEN(value)+1);
pMe->mobile = STRCPY(pMe->mobile, value);
Rachel, I see that you have to enter in BREW programming, once acquired experience in Java.
char * s = NULL - this does not create an empty string, as in Java. It's simply creating a zero-initialized pointer to a 'char' data type. Attempting to call STRLEN or STRCPY on that pointer will cause an error.
Here is a test piece, which is working correctly, not causing the error:
{
char* value = "";
char *mobile = (char*)MALLOC(STRLEN(value)+1);
STRCPY(mobile, value);
FREE(mobile);
}
Rachel, I recommend you to allocate memory for the maximum future size of string, to avoid in the future REALLOC calls.
Something like:
char * s = MALLOC (128) / / assume that the length of the line will be a maximum of 128 characters.

Rachel wrote:I face Memory Access STRCPY error for the following code:
char* value = NULL;
pMe->mobile = (char*) MALLOC(STRLEN(value)+1);
pMe->mobile = STRCPY(pMe->mobile, value);
Rachel, I see that you have to enter in BREW programming, once acquired experience in Java.
char * s = NULL - this does not create an empty string, as in Java. It's simply creating a zero-initialized pointer to a 'char' data type. Attempting to call STRLEN or STRCPY on that pointer will cause an error.
Here is a test piece, which is working correctly, not causing the error:
{
char* value = "";
char *mobile = (char*)MALLOC(STRLEN(value)+1);
STRCPY(mobile, value);
FREE(mobile);
}
Rachel, I recommend you to allocate memory for the maximum future size of string, to avoid in the future REALLOC calls.
Something like:
char * s = MALLOC (128) / / assume that the length of the line will be a maximum of 128 characters.