| | |
Access Violation
Thread Solved |
•
•
Join Date: Oct 2006
Posts: 58
Reputation:
Solved Threads: 0
Consider the following code:
When compiling with Borland C it worked fine. However when I tried cimpiling it with VS 2005 I got the following error:
"Unhandled exception at 0x00413529 in Learning C.exe: 0xC0000005: Access violation writing location 0x00415645."
When I changed the code to:
Instead of
It worked fine. I found this resolution in a forum.
But based on what I learnt in C I don't understand why it did not work in VS. And why by making it an array rather than a pointer it made a difference?
#include<stdio.h> #define SET_BIT(buf,n,val)buf[n]=val int main() { char ch='D'; char *name="Yankee Duddle"; int i=5; SET_BIT(name,i,ch); printf("%s",name); }
When compiling with Borland C it worked fine. However when I tried cimpiling it with VS 2005 I got the following error:
"Unhandled exception at 0x00413529 in Learning C.exe: 0xC0000005: Access violation writing location 0x00415645."
When I changed the code to:
char name[]="Yankee Duddle";
char *name="Yankee Duddle";
It worked fine. I found this resolution in a forum.
But based on what I learnt in C I don't understand why it did not work in VS. And why by making it an array rather than a pointer it made a difference?
In case
Whereas in case of
char *name="Yankee Duddle"; string literal turns into an unnamed, static array of characters, and this unnamed array may be stored in read-only memory, and which therefore cannot necessarily be modified. Trying to modify it is undefined behaviour. Whereas in case of
char name[]="Yankee Duddle"; you can modify the contents safely. •
•
•
•
When compiling with Borland C it worked fine. However when I tried cimpiling it with VS 2005 I got the following error:
"Unhandled exception at 0x00413529 in Learning C.exe: 0xC0000005: Access violation writing location 0x00415645."
But based on what I learnt in C I don't understand why it did not work in VS. And why by making it an array rather than a pointer it made a difference?
char name[]="Yankee Duddle"; the elements can be modified.
calling the SET_BIT in main you are trying to modify the value in char *name.
[EDIT]: Sorry, SPS your posted while I was writing this. Making this post a repetition.
Last edited by Aia; Aug 19th, 2007 at 1:35 pm.
•
•
Join Date: Oct 2006
Posts: 58
Reputation:
Solved Threads: 0
I think I found the answer (if anyone else has this problem):
http://msdn2.microsoft.com/en-us/lib...yy(vs.71).aspx
http://msdn2.microsoft.com/en-us/lib...yy(vs.71).aspx
![]() |
Similar Threads
- Access violation reading location 0xcccccccc (C++)
- Access violation in C (C)
- access violation at address 0055E531 in module (Windows NT / 2000 / XP)
- Unhandled exception in IEXPLORER.EXE (SHDOCVW.DLL): 0xC0000005: Access Violation (Web Browsers)
- access violation at 0x00000024 (Windows NT / 2000 / XP)
- How do I access variables in my queue? (C++)
- Access Violation (Segmentation Fault) + atol (C++)
- unhandaled exception,0X000005:access violation (C)
- Accession Violation message on installation of program (Windows NT / 2000 / XP)
Other Threads in the C Forum
- Previous Thread: need help on simple turbo C program.. thx
- Next Thread: Can i program an usb port?
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






