Why am I getting EXC_BAD_ACCESS here?

  • Thread starter Thread starter Jamin2112
  • Start date Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
4 replies · 2K views
Jamin2112
Messages
973
Reaction score
12
Screenshot:

wB7Wnhg.png
Here's a full code dump if you think the issue could depend on a line not shown in the screenshot: http://codepad.org/zSE1vobz
 
Physics news on Phys.org
strcmp compares two strings. You don't show enough code so that I can determine what rt->fx represents, but 'x' is a character constant. Since both args of strcmp are strings (i.e., of type char * or char []), strcmp attempts to access the characters that are pointed to by its two arguments. Passing in 'x' (which happens to have an ASCII code of 0x78) causes strcmp to attempt to access the byte at memory location 0x78. This causes the access error that you are seeing.

All of the string processing functions that are declared in string.h take pointers for their string arguments.
 
Mark44 said:
strcmp compares two strings. You don't show enough code so that I can determine what rt->fx represents, but 'x' is a character constant. Since both args of strcmp are strings (i.e., of type char * or char []), strcmp attempts to access the characters that are pointed to by its two arguments. Passing in 'x' (which happens to have an ASCII code of 0x78) causes strcmp to attempt to access the byte at memory location 0x78. This causes the access error that you are seeing.

All of the string processing functions that are declared in string.h take pointers for their string arguments.

Thanks!

I knew that strcmp compares 2 strings ... I'm just an idiot who put 'x' instead of "x".
 
Carno Raar said:
Why do people use malloc? :-)
It's faster than new, by a lot. If your'e doing low level memory handling, it allows allows you to do some nice tricks such as explicitly saying when you want a constructor called, or weird things like replacing new, delete, new, delete <- actually allocates and frees memory twice with malloc, ctor, dtor, ctor, dtor, free <- reuses the memory.

That also appears to be C, not C++. The only way to dynamically allocate memory in C is *alloc.