How to test a large CString to find a smaller CString

Working on this lab, and have 9 hours to submit it. Thought I had it finished, but the professor clarified instructions and I have to rewrite some code.

I'm passing a c-string into a function, such as "blossom", upcasing it and a state flower name member of a struct, and then testing the longer upcased struct flower name, such as "Morning Blossom" to see if it contains "blossom". Without static casting to strings, I am completely lost on how to do this. Help greatly appreciated.

Here's my code so far,

//------------------------------------------------------------------------------------------------
//Function 10 - OutputStateAndFlowerNames
//Outputs a list of state names and their flowers when the flower name contains a string passed in
//------------------------------------------------------------------------------------------------
void OutputStateAndFlowerNames(ofstream& fout, stateStructType stateInfo[], char testName[])
{
int index;
int testIndex;
int matchLength;
int testNameLength;
int flowerNameLength;

bool flowerFound = false;

flowerNameType upcasedTestName;
flowerNameType upcasedStateFlowerName;

UpcaseCharArray(testName, upcasedTestName, testNameLength);

//Outputs a task heading and output alignment heading to the output file
OutputTaskHeading(fout, 10,
"Outputs a list of state names whose flower names contain a string passed in");
OutputStateAndFlowerHeader(fout);

//Step through all elements of the array, searching each state name for test name
for (index = 0; index < 50; index++)
{
UpcaseCharArray(stateInfo[index].flowerName, upcasedStateFlowerName, flowerNameLength);

if (???)
{
fout << stateInfo[index].stateName << setw(SCREEN_WIDTH / 2 + 12) <<
stateInfo[index].flowerName << endl;
flowerFound = true;

}
}

//Determine if no flower was matched to the test value
if (!flowerFound)
{
//Output error message to the output file
fout << "No flower in any state contains the given values." << endl;
}

//Outputs divider to the output file and ends line for next output
OutputDivider(fout, '*', SCREEN_WIDTH);
fout << endl;
}
Last edited on
What would strstr return if a match was not found? And what would it return if a match was found, the location of the pointer? I need to know how to test that statement, such as strstr(upcasedStateFlowerName, upcasedTestName) - when I say

if (strstr(upcasedStateFlowerName, upcasedTestName) != '\0')
{
//Output
}

ALL the states are output. What would I use as a conditional here?
Last edited on
What would strstr return if a match was not found? And what would it return if a match was found, the location of the pointer?

All that is explained clearly in the link ShiftLeft posted.

Topic archived. No new replies allowed.