c++ - char pointer comparison error -


using c++ mfc , visual studio 2008.

sorry newbie question, i'm not sure why isn't working. i'm making function finds standard illegal characters xml in char * that's passed it, strange error.

char* xmlillegalcharacterparser(char *input){     char *temp;     (size_t = 0; < strlen(input); i++){         if(input[i] == "\"" || input[i] == "\'" || input[i] == "&")     }     return temp; }  1>.\fileimport.cpp(868) : error c2446: '==' : no conversion 'const char *' 'int' 

i can't life of me figure out why isn't working. syntax have wrong?

ps: know have 3 of characters there. got error , wanna fix before add other two.

here after code:

char* xmlillegalcharacterparser(char *input){ char *temp; (size_t = 0; < strlen(input); i++){     switch(input[i]){         case '\"':             strcat_s(temp, 6, "&quot;");             break;         case '\'':             strcat_s(temp, 6, "&apos;");             break;         case '&':             strcat_s(temp, 5, "&amp;");             break;         case '<':             strcat_s(temp, 4, "&lt;");             break;         case '>':             strcat_s(temp, 4, "&gt;");             break;         default:             strcat_s(temp, 1, (const char*)input[i]);             break;     } } return temp; } 

you mean single quotes instead of double:

input[i] == '"'             ^ ^ 

same goes other cases. when use double quotes, in "&", create "string literal". input[i] character: can't compare string literal character.

what's more, if input[i] string literal, wouldn't right way compare c-style strings in c++.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -