Display Invisible Characters

◀ Tokenize a String▶ Advanced
Amazon Sometimes in debugging your program, you wish to see what a string or a char really contains but it may contain invisible characters such as newline, carriage return, and space. As an example, you are writing an HTTP client who needs to send an HTTP request to an HTTP server in order to retrieve some document. The HTTP request needs to conform to rules governing interactions between an HTTP client and an HTTP server.

In such a situation, you need to make sure the request your client sends is valid. Here are some simple functions to achieve this end:
void examineChar(char c){
if(c=='\n') cout<<"\\n"; else if(c=='\r') cout<<"\\r"; else if(c=='\b') cout<<"\\b"; else if(c=='\t') cout<<"\\t"; else if(c=='\a') cout<<"\\a"; else if(c=='\v') cout<<"\\v"; else if(c=='\0') cout<<"\\0"; else cout<<c; } void examineCharStar(char *cs){ int i; for(i=0;i<strlen(cs);i++) examineChar(cs[i]);
} void examineString(string s){ int i; if(s!="") for(i=0;i<s.length();i++) examineChar(s[i]); }
Note that a string can be “” but a char cannot be ‘’.
◀ Tokenize a String▶ Advanced

fShare
Questions? Let me know!