#include <string>
#include <iostream>
using namespace std;
bool containsString(const char sourceString[], const char searchString[]) {
//we are assuming 'sourceString' and 'searchString' are pointing at two null-terminated char arrays...
unsigned int sourceStringSize = 0;
while (sourceString[sourceStringSize] != '\0') {
sourceStringSize++; //increment size
}
unsigned int searchStringSize = 0;
while (searchString[searchStringSize] != '\0') { //loop while the current character isn't the null character
searchStringSize++; //increment size
}
if (searchStringSize < sourceStringSize) { //meaning the string searched for is shorter than the source string
//first check to see if the special string "A-Za-z" was passed into the 'searchString' parameter...
int searchStringIsSpecialString = strcmp(searchString, "A-Za-z");
if (searchStringIsSpecialString == 0) { //then search for a character of the source string in the range of A-Z, or a-z
for (unsigned int i = 0; i < sourceStringSize; i++) {
if (sourceString[i] >= 'A') {
if (sourceString[i] == 'A') {
return true; //at the first 'A' character
}
else if (sourceString[i] > 'A') {
if (sourceString[i] <= 'Z') {
return true; //at the first character from 'B' through 'Z'
}
else if (sourceString[i] > 'Z') {
if (sourceString[i] < 'a') {
//check to make sure that its not the end of the source string
if (i == sourceStringSize - 1) {
return false; //since we're at the last character of the sourceString, and no character in the range of A-Z or a-z was found
}
else {
//continue checking characters of the sourceString...
}
}
else if (sourceString[i] >= 'a') {
if (sourceString[i] == 'a') {
return true; //at the first 'a' character
}
else if (sourceString[i] > 'a') {
if (sourceString[i] <= 'z') {
return true; //at the first 'b' through 'z' character
}
else if (sourceString[i] > 'z') {
//check to make sure that its not the end of the source string
if (i == sourceStringSize - 1) {
return false; //since we're at the last character of the source string, and no character in the range of A-Z or a-z was found
}
else {
//continue checking characters of the sourceString...
}
}
}
}
}
}
}
}
}
//if it got this far, then search string wasn't "A-Za-z"...so we now check to see if the searchString is contained in the sourceString...
unsigned int found;
string sourceStringString = sourceString;
found = sourceStringString.find(searchString);
if (found != string::npos) { //i.e. searchString wasn't found in searchString
return true;
}
else {
return false;
}
}
else if (searchStringSize == sourceStringSize) { //meaning the two strings have the same length
//first check for the special "A-Za-z" string...
int searchStringIsSpecialString = strcmp(searchString, "A-Za-z");
if (searchStringIsSpecialString == 0) { //then search for a character of the source string in the range of A-Z, or a-z
for (unsigned int i = 0; i < sourceStringSize; i++) {
if (sourceString[i] >= 'A') {
if (sourceString[i] == 'A') {
return true; //at the first 'A' character
}
else if (sourceString[i] > 'A') {
if (sourceString[i] <= 'Z') {
return true; //at the first character from 'B' through 'Z'
}
else if (sourceString[i] > 'Z') {
if (sourceString[i] < 'a') {
//check to make sure that its not the end of the source string
if (i == sourceStringSize - 1) {
return false; //since we're at the last character of the source string, and no character in the range of A-Z or a-z was found
}
else {
//continue checking characters...
}
}
else if (sourceString[i] >= 'a') {
if (sourceString[i] == 'a') {
return true; //at the first 'a' character
}
else if (sourceString[i] > 'a') {
if (sourceString[i] <= 'z') {
return true; //at the first 'b' through 'z' character
}
else if (sourceString[i] > 'z') {
//check to make sure that its not the end of the source string
if (i == sourceStringSize - 1) {
return false; //since we're at the last character of the source string, and no character in the range of A-Z or a-z was found
}
else {
//continue checking characters...
}
}
}
}
}
}
}
}
}
//if it got this far, then the special string wasn't passed, and we can check to see if the source string contains the search string
int sourceStringIsSameAsSearchString = strcmp(sourceString, searchString);
if (sourceStringIsSameAsSearchString == 0) { //meaning the two strings are the same
return true;
}
else {
return false;
}
}
else if (searchStringSize > sourceStringSize) { //meaning that the string searched for is longer than the source string
//first check for the special "A-Za-z" string...
int searchStringIsSpecialString = strcmp(searchString, "A-Za-z");
if (searchStringIsSpecialString == 0) { //then search for a character of the source string in the range of A-Z, or a-z
for (unsigned int i = 0; i < sourceStringSize; i++) {
if (sourceString[i] >= 'A') {
if (sourceString[i] == 'A') {
return true; //at the first 'A' character
}
else if (sourceString[i] > 'A') {
if (sourceString[i] <= 'Z') {
return true; //at the first character from 'B' through 'Z'
}
else if (sourceString[i] > 'Z') {
if (sourceString[i] < 'a') {
//check to make sure that its not the end of the source string
if (i == sourceStringSize - 1) {
return false; //since we're at the last character of the source string, and no character in the range of A-Z or a-z was found
}
else {
//continue checking characters...
}
}
else if (sourceString[i] >= 'a') {
if (sourceString[i] == 'a') {
return true; //at the first 'a' character
}
else if (sourceString[i] > 'a') {
if (sourceString[i] <= 'z') {
return true; //at the first 'b' through 'z' character
}
else if (sourceString[i] > 'z') {
//check to make sure that its not the end of the source string
if (i == sourceStringSize - 1) {
return false; //since we're at the last character of the source string, and no character in the range of A-Z or a-z was found
}
else {
//continue checking characters...
}
}
}
}
}
}
}
}
}
return false; //since the string searched for has a longer string than the one being checked, meaning there is no
//possibility of the shorter string fully containing the longer string
}
return false;
}
int main() {
char array[] = "enum DAY {";
if (containsString(array, ";")) {
cout<< "The array contained the string." <<endl;
}
return 0;
}