Quote:Original post by the_dannobot
Here's how I would do it.#define STRING_LENGTH 255
Ewww. Yuck. It was better before you edited and fell back on the gutter of the preprocessor. This is C++. At the very least use a const integral type rather than tromping on everybodies names. Also both domain and the memset are totally redundant. And why a STRING_LENGTH of 255 rather than 256?
Seriously, it's much more readable, maintainable and extensible to use the SC++L and convert from and to char * string only when accesing C api calls:
// assumes getSiameseOrEgyptianMau is to be passed as a callback function// to a C api, so uses char const * const parametersint getSiameseOrEgyptianMau(char const * const filenameCharArray, char const * const inUrlCharArray){ std::string filename(filenameCharArray); std::ifstream reader(filename.c_str()); if (!reader) { std::cout << "Error opening file " << filename << '\n'; return -1; } std::string inUrl(inUrlCharArray); std::string domain; while (reader >> domain) { if(domain == inUrl) { std::cout << "match found\n"; break; } } return 0;}
Enigma