Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having a problem with this segment of my code, It gives me this error.
Unhandled exception at 0x5518c1a8 (msvcr100d.dll) in Eyeball.exe: 0xC0000005: Access violation reading location 0x525c3a43.

This is the code...
C++
if ((argc>=4) && (strcmp(argv[3], "m")==0))
    more=1;
result = atoi(argv[2]);
packetCount=0;
Posted
Updated 27-Aug-11 11:26am
v2

1 solution

the string you pass to atoi is not null terminated

you have less than 3 arguments. You haven't ensured that you have 3 arguments thus result = atoi(argv[2]); might fail.

Stepping through your code line by line, with the debugger, will allow you to find the line that fails and it should be more obvious to you what the reason for the error is.
 
Share this answer
 
v3
Comments
Member 7766180 27-Aug-11 17:30pm    
It fails on the atoi(argv[2]) line. Is there a way to return a 0 if it is null? Would that work? Is there a way to check if it has 3 arguments? Thanks
mbue 27-Aug-11 17:56pm    
Yes indeed:
result = 2<argc?atoi(argv[2]):0;
Regards.
Member 7766180 27-Aug-11 18:45pm    
Thank you! How can I give you credit? Post as a new solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900