计算char的ascii值之和

时间:2015-09-28 03:28:18

标签: c++ char sum ascii

我需要创建一个哈希函数,该函数应该在给定的char中返回mod值为100(即HASH_TABLE_SIZE)的ASCII值之和,但我似乎没有得到正确的输出。我该如何纠正?

function doSomethingElse(var1, var2) {
    var promise = findData(var1, var2);

    promise.then(function(data) {
    // make another ajax request with the ajax data from promise
    }, function(error) { });
}

1 个答案:

答案 0 :(得分:1)

请勿在流程中间return

试试这个:

int string_set::hash_function(const char *s) {

    int h = 0;
    for (int i =0; s[i] != '\0'; i++) // the loop condition didn't seem good
    {
        // the cast to unsigned char may be needed for system in which the type char is signed
        h = (h + (unsigned char)s[i]) % HASH_TABLE_SIZE;
    }
    return h;
}

只有当您的系统使用ASCII代码作为char的字符代码时,此代码才能正常工作。