473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

exception : 0xC0000005: Access Violation

Hi,

I am getting the following exception

First-chance exception in TestMansoor.exe: 0xC0000005: Access Violation

When i run the following code

1 int main(void)
2 {
3 char* str1 = "MA";
4 char s = str1[0];
5 str1[0] = 'r';
6 return 0;
7 }

i'm getting exception on line 5. Why?

Bye.

Nov 7 '05 #1
4 24156

batista wrote:
Hi,

I am getting the following exception

First-chance exception in TestMansoor.exe: 0xC0000005: Access Violation

When i run the following code

1 int main(void)
2 {
3 char* str1 = "MA";
4 char s = str1[0];
5 str1[0] = 'r';
6 return 0;
7 }

i'm getting exception on line 5. Why?


str is a constant string , you can only access it. If you want to
change the contents of str, you will either have to declare it as an
array of allocate memory for it.

Nov 7 '05 #2
batista wrote:
Hi,

I am getting the following exception

First-chance exception in TestMansoor.exe: 0xC0000005: Access Violation

When i run the following code

1 int main(void)
2 {
3 char* str1 = "MA";
4 char s = str1[0];
5 str1[0] = 'r';
6 return 0;
7 }

i'm getting exception on line 5. Why?

Bye.


becouse "MA" is a string iteral, and as such cant be modified, even
though its possilble to get a non const pointer to it for some bizzare
reason

your code is more less equivalent of

((char*)"MA")[0] = 'r';

if you want to get a copy of "MA" what you want to do is
char str1[] = "MA";
now str1[0] is modifiable
Nov 7 '05 #3
batista wrote:
Hi,

I am getting the following exception

First-chance exception in TestMansoor.exe: 0xC0000005: Access Violation

When i run the following code

1 int main(void)
2 {
3 char* str1 = "MA";
4 char s = str1[0];
5 str1[0] = 'r';
6 return 0;
7 }

i'm getting exception on line 5. Why?

Line 3 should read:

const char* str1 = "MA";

It is specifically allowed by the standard as your original because of
the volume of legacy code that would otherwise break. (IMHO a bad move
by the standards comittee.)

You can however rewrite line 3 like:

char str1[] = "MA";

.... now you're free to change the three characters that is str1.
Nov 7 '05 #4
In article <11*********************@g49g2000cwa.googlegroups. com>,
batista <sa*********@gmail.com> wrote:
Hi,

I am getting the following exception

First-chance exception in TestMansoor.exe: 0xC0000005: Access Violation

When i run the following code

1 int main(void)
2 {
3 char* str1 = "MA";
4 char s = str1[0];
5 str1[0] = 'r';
6 return 0;
7 }

i'm getting exception on line 5. Why?


Check out http://www.comeaucomputing.com/techtalk/#stringliteral
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 8 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Toon Huysmans | last post by:
Hi, I have a mind boggling error in VC++ .NET. An exception THException is being thrown, but it seems to cause an accessviolation, but the code is so simple that I cant figure out where the...
2
by: Koen Appeltans | last post by:
Hi all, Since yesterday I'm unable to lauch the enterprise manager, it gives the following error : Unhandled exception at 0x0101f07e in mmc.exe: 0xC0000005: Access violation reading location...
2
by: bhreddy | last post by:
Hi All, Can someone help me out how can I resolve the error "0xC0000005: Access violation reading location 0x513112f4"? Steps I followed... 1. I ran the application at DOS prompt 2. After...
1
by: William Brogden | last post by:
I am trying to use the php_java.dll and php5servlet.dll - from pecl-5.1.4-win32.zip - dated 5/04/2006 to execute php in a Tomcat5.5.9 servlet environment. Java 1.5.0 I finally got a configuration...
2
by: Adam Hartshorne | last post by:
Hi All, I have the following problem. I have just installed visual studio 2003 (v7.1) on a new laptop. I also have the same version installed in a desktop pc. As a test, i tried compiling some...
2
by: Abubakar | last post by:
Hi all, I'm writing an app in vc++ 2k5 (all native/unmanaged). This application does a lot of multithreading and socket programming. Its been months since I'm developing this application, at...
5
by: B. | last post by:
I know there is similar post few years back, but it didn't help solving my problem: We have a big project. Our legacy code is ported to VC++ 2005 recently. We have new feature written in C#.Net....
0
by: Mohammad Omer | last post by:
Hi, I am working on MFC base SDI application using vs2k5. When I close my application, exception shows up in "wincore.cpp" line 449, statement "lResult = CallWindowProc(oldWndProc, hWnd, nMsg,...
4
by: Alerion | last post by:
Hello everyone, I've been a regular of this forum but this is my first post, generally I can find the answer to my question already, but this time I'm having a somewhat specific problem. For...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.