Mega Code Archive

 
Categories / C++ Tutorial / String
 

Search a null-terminated string

#include <iostream> #include <cstring> using namespace std; int main() {   const char *url = "server.com";   const char *url2 = "Apache.org";   const char *emailaddr = "Herb@server.com";   const char *tld[] = { ".com", ".net", ".org" };   const char *p;   // determine if url and url2 contain .com, .net, or .org.   for(int i=0; i < 3; i++) {     p = strstr(url, tld[i]);     if(p) cout << url << " has top-level domain " << tld[i] << endl;     p = strstr(url2, tld[i]);     if(p) cout << url2 << " has top-level domain " << tld[i] << endl;   }   return 0; }