strcmp or string::compare?

For C++, use std::string and compare using string::compare. For C use strcmp. If your (i meant your programs) strings (for some weird reason) aren’t nul terminated, use strncmp instead. But why would someone not use something as simple as == for std::string ?

Concatenate char arrays in C++

In C++, use std::string, and the operator+, it is designed specifically to solve problems like this. #include <iostream> #include <string> using namespace std; int main() { string foo( “hello” ); string test( “how are” ); cout << foo + ” , ” + test; return 0; }

C split a char array into different variables

#include<string.h> #include<stdio.h> int main() { char input[16] = “abc,d”; char *p; p = strtok(input, “,”); if(p) { printf(“%s\n”, p); } p = strtok(NULL, “,”); if(p) printf(“%s\n”, p); return 0; } you can look this program .First you should use the strtok(input, “,”).input is the string you want to spilt.Then you use the strtok(NULL, “,”). If … Read more

Illegal Escape Character “\”

The character ‘\’ is a special character and needs to be escaped when used as part of a String, e.g., “\”. Here is an example of a string comparison using the ‘\’ character: if (invName.substring(j,k).equals(“\\”)) {…} You can also perform direct character comparisons using logic similar to the following: if (invName.charAt(j) == ‘\\’) {…}