Floating point exception ????

This is a discussion on Floating point exception ???? within the C Programming forums, part of the General Programming Boards category; Hey guys.. I'm implementing a simple hash function to test my hash table ... but when i compute value for ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    51

    Floating point exception ????

    Hey guys..

    I'm implementing a simple hash function to test my hash table ... but when i compute value for the hash value, i get this error of which i've never encountered, if i remember

    Code:
    Floating point exception
    Here's wat's my functions look like

    Code:
    static void
    hashtable_insert(HashTable *ht, char *key, char *value)
    {
        int tablefull = 0;
        int hashval;
        hashval = hash_func(key, value, ht);
        tablefull = hashval;
        int init_hashval = hashval;
    
        if(key == '\0')
        {
            strcpy(ht->table[hashval].key, key);
            strcpy(ht->table[hashval].value, value);
        }
        else
        {
            while(key != '\0')
            {
                if(tablefull == ht->num_items)
                {
                       hashval = 0;
                       tablefull = 0;
                }
    
                strcpy(ht->table[hashval+1].key, key);
                strcpy(ht->table[hashval+1].value, value);
                tablefull++;
    
                if(hashval == init_hashval)
                {
                        perror("Table overflow!!\n");
                        exit(EXIT_FAILURE);
                }
            }
        }
    
    }
    
    int hash_func(char *key, char *value, HashTable *ht)
    {
            int i, hashval, num_items;
            num_items = ht->num_items;
    
            for(i=0; i == '\0'; i++)
            {
                    hashval = (int)(key+i) + (int)(value+i);
            }
    
            hashval = hashval % num_items;
    
           return (int)hashval;
    }
    thx

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by wuzzo87 View Post
    Hey guys..

    I'm implementing a simple hash function to test my hash table ... but when i compute value for the hash value, i get this error of which i've never encountered, if i remember

    Code:
    Floating point exception
    It doesn't sound like a compile-time issue, it sounds like a run-time issue.

    And you haven't posted enough code to diagnose it, unless I'm off again.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    int hash_func(char *key, char *value, HashTable *ht)
    {
            int i, hashval, num_items;
            num_items = ht->num_items;
    
            for(i=0; i == '\0'; i++)
            {
                    hashval = (int)(key+i) + (int)(value+i);
            }
    
            hashval = hashval % num_items;
    
           return (int)hashval;
    }
    Why do you have a loop if all you do is execute it once? Also "key" is a character pointer, to which you add i to (which is only ever zero), which you're not actually dereferencing, which means you're not actually looking at the key string at all. You also do the same thing with value. So in short, your loop sucks.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    51
    sorry guys,
    my fault....
    i'm cleaning up the whole code...

    There seem to be something wrong with my insertion to the table..
    but i'll try to fix that up by myself 1st..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Decimal places on Floating point number
    By manutdfan in forum C Programming
    Replies: 1
    Last Post: 10-29-2006, 11:56 AM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 11:07 AM
  3. floating point question
    By Eric Cheong in forum C Programming
    Replies: 8
    Last Post: 09-10-2004, 10:48 PM
  4. 2 questions about floating point and %
    By ams80 in forum C Programming
    Replies: 2
    Last Post: 08-14-2002, 10:55 AM
  5. Replies: 2
    Last Post: 09-10-2001, 12:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21