Thread: strcmp problems

  1. #1
    Unregistered
    Guest

    strcmp problems

    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?

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    can we see some code?
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Unregistered
    Guest
    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;
    }

  4. #4
    Unregistered
    Guest
    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;

  5. #5
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    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.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problems with strcmp
    By loopymoo26 in forum C Programming
    Replies: 6
    Last Post: 05-13-2009, 02:10 AM
  2. strcmp
    By kryonik in forum C Programming
    Replies: 9
    Last Post: 10-11-2005, 11:04 AM
  3. strcmp() \ flushing output
    By Brain Cell in forum C Programming
    Replies: 7
    Last Post: 01-17-2005, 01:28 PM
  4. seg fault with strcmp
    By samps005 in forum C Programming
    Replies: 2
    Last Post: 05-04-2003, 04:32 PM
  5. strcmp, any borders?
    By demonus in forum C Programming
    Replies: 3
    Last Post: 11-15-2002, 02:48 AM