I for trim string "char array in c and c++ or char pointer" use this function:
inline char * trimRight(char * str)
{
    char * end = str + strlen(str);
    while(str != end)
    {
        end--;
        switch(*end)
        {
            case ' ':
            case '\t':
            case '\n':
            case '\v':
            case '\f':
            case '\r':
            break;
            default:
                *(end+1) = '\0';
                return end+1;
        }
    }
    return str;
}
but return this error (reason in code *(end+1) = '\0' ) :
An unhandled exception of type 'System.AccessViolationException' occurred in x.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
please help me.
 
    