Advertisement

QUICK question

Started by July 24, 2003 01:33 PM
4 comments, last by TheProx 21 years, 7 months ago
is there a way to search for a letter in a string?
NARF - Pinky and the Brain
int i = 0;
char tempLetter = string[0];
While(tempLetter != targetLetter)
{
i++;
tempLetter = string;
}

if(tempLetter == targetLetter)
cout << targetLetter << "is letter number " << i + 1;
else
cout << targetLetter << "not found" << endl;

I think that should do it.


When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...
Without order nothing can exist - without chaos nothing can evolve.
Advertisement
char alpha[36] = {''A'',''B'',''C'',''D'',''E'',''F'',''G'',''H'',''I'',''J'',''K'',''L'',''M'',''N'',''O'',''P'',''Q'',''R'',''S'',''T'',''U'',''V'',''W'',''X'',''Y'',''Z'',''<'',''>'',''.''<'',''('','')'',''+'',''-'',''='',''/'',''*''};

this is what i have, yet, it comes up with error C2064
:term does not evaluate to a function
NARF - Pinky and the Brain
think you''ve missed a comma
''>'', ''.''<'', ''('',
also, to search for a string you can use strstr; look it up in help for more info.
Try strchr() or strcspn(), don''t forget to include string.h
you can find the reference doc on www.cplusplus.com
Paulhttp://members.lycos.co.uk/p79
If you''re using C++, with proper C++ strings:

myString.find(myChar);


How appropriate. You fight like a cow.

This topic is closed to new replies.

Advertisement