char *strlwr(char *string);
char *a="VIJAY";
char *c;
c=strlwr(a);
printf("%s",c)
I am getting memory violation error at step 4.
Thanks,
Vijay
char *strlwr(char *string);
char *a="VIJAY";
char *c;
c=strlwr(a);
printf("%s",c)
I am getting memory violation error at step 4.
Thanks,
Vijay
1. You did not use code tagsOriginally Posted by Vijay_K
2. You did not provide a complete program
3. You did not show the implementation of "strlwr()"
There could be several reasons for this error, but we can't say for sure without seeing how the function is implemented.
Last edited by Matticus; 02-03-2016 at 06:39 AM.
Hi Matticus,
Dont know what you are asking, I am newbie in C, please help. I just want to know what is wrong in step 3;
Here is the code:
Error:Code:Action() { char *a="SAM"; char *c; c=strlwr(a); lr_output_message("%s",ptr_one); return 0; }
Action.c(9): Error: C interpreter run time error: Action.c (9): Error -- memory violation : Exception ACCESS_VIOLATION received.
You were already asked, but I'll ask again. What is strlwr? Where did you find it, and what does it do? Do you have the source code for it, or is it a library function somewhere?
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
"strlwr()" is not a standard C library function, but apparently some implementations modify the string it receives.
Try declaring "a" as an array:
char a[]="SAM";
Almost certainly, strlwr() will try to do something with the string in place, rather than making a copy of it first.
So you need to know that something like
char *s = "hello";
stores "hello" in read-only memory.
If you try to modify it, you get an access violation.
Compare this with
char s[] = "hello";
which allocates some memory (called s), and populates that with the characters "hello".
Now this is something you should be able to pass to strlwr().
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Hi,
Here is the link you will understand. http://lrhelp.saas.hp.com/en/latest/....htm#kanchor87
I want to save it some variable that is returned through the function strlwr.
But I am not able to save it in a variable why is this?
Here you can see the example as well, they are using strdup, I dont know why they are using it, big confusion
Last edited by Vijay_K; 02-03-2016 at 10:39 AM.
Matticus and Salem have answered your original question.
You can't pass a pointer to a string literal to strlwr since string literals are often stored in memory you can't write to.
Instead you must create your own array for the string data and pass that.
The reason they use strdup in that example is because strlwr modifies the input string and they don't want to modify the original string. So they make a copy of it with strdup, call strlwr, do whatever needs to be done with it, and then they free the copy.
Last edited by algorism; 02-03-2016 at 10:55 AM.