I am comparing a char* to another char* inside a dynamically allocated array of structures. However when I try to compare the stirings I get this error:
"First-chance exception in smilest.exe: 0xC0000005: Access Violation."
Any thoughts?
I am comparing a char* to another char* inside a dynamically allocated array of structures. However when I try to compare the stirings I get this error:
"First-chance exception in smilest.exe: 0xC0000005: Access Violation."
Any thoughts?
can we see some code?
All spelling mistakes, syntatical errors and stupid comments are intentional.
here's some code:
int st_lookup(SymbolTable stable, char *p_vname) {
int index;
for (index = stable.st_size-1; index > -1; --index) {
if(strcmp(stable.p_stes[index].p_vname,p_vname)==0)
return index;
}
return -1;
}
also here are my structs:
typedef union InitialValue {
int int_val; /* integer variable initial value */
float flp_val; /* float variable initial value */
} InitialValue;
typedef struct SymbolTableEntry {
char *p_vname; /* pointer to lexeme (name) in CA */
int f_line; /* first line of appearance */
InitialValue i_value; /* variable initial value */
unsigned short status_field; /* variable record status field*/
size_t ds_offset;/* offset from the data segment beginning */
}SymbolTableEntry;
typedef struct SymbolTableDescriptor {
SymbolTableEntry *p_stes; /* pointer to array of STES */
int st_size; /* size in number of STES elements */
int st_offset; /*offset in number of STES elements */
Buffer *st_lexbuff; /* pointer to lexeme buffer descriptor */
} SymbolTable;
0xC0000005: Access Violation
This means that it's a memory error not strmp()
Make sure that you have not freed the memory that you are
trying to compare.
Post an example of where the program crashes.
An access violation means that strcmp is being passed an invalid pointer for either or both arguments. I'd recommend stepping through your code up to that point and finding the source of the corruption.
-Prelude
My best code is written with the delete key.