Finding the first non-repeating character in a string
Let's try a solution that doesn't use an array with all the required bookkeeping.  The following code works, and bypasses the problems others have pointed out.

First, a quick template function that searches for duplicates given a char:

template &lt;typename T&gt;
inline bool repeated(char c, T first, T last) {
    size_t count = 0;
    while (first != last) {
        if (*first == c) ++count;
        if (count &gt; 1) return true;
        ++first;
    }
    return false;
}


Now we create a set of unique characters and then scan the string to see if there are any duplicates.  If there are, we remove the char from the set and continue to the next one.

char FirstNonRepeatedchar(const char* str, int len) {
    auto uniq = std::set&lt;char&gt;(str, str + len);
    auto first = str;
    auto last = str + len;
    while (first != last) {
        if (auto it = uniq.find(*first) != uniq.end()) {
            if (!repeated(*first, str, str + len)) return *first;
            uniq.erase(it);
        }
        ++first;
    }
    return '@';
}