string.find() issue

Hello I'm having an issue with the string.find() string::npos function. Here is my code... This is my custom function for searching strings...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
string srchSTRbasic( string INPUT )
	{
		for( int i=0; i < INPUT.length(); i++ )			{ INPUT[i] = tolower(INPUT[i]); }

		string rtr;
		string::size_type Loc;

		if( INPUT != "" ) {
			
			// Funcs
			if( Loc = INPUT.find("stats", 0) != string::npos )				{ return ("stats"); }
			else if( Loc = INPUT.find("reset", 0) != string::npos )			{ return ("reset"); }
			else if( Loc = INPUT.find("restart", 0) != string::npos )		{ return ("reset"); }

			// Yes, No... Etc
			else if( Loc = INPUT.find("yes", 0) != string::npos )			{ return ("yes"); }
			else if( Loc = INPUT.find("ok", 0) != string::npos )			{ return ("yes"); }
			else if( Loc = INPUT.find("k", 0) != string::npos )				{ return ("yes"); }
			else if( Loc = INPUT.find("alright", 0) != string::npos )		{ return ("yes"); }
			else if( Loc = INPUT.find("y", 0) != string::npos )				{ return ("yes"); }

			// Up
			else if( Loc = INPUT.find("up", 0) != string::npos )			{ return ("up"); }
			else if( Loc = INPUT.find("ascend", 0) != string::npos )		{ return ("up"); }

			// Down
			else if( Loc = INPUT.find("down", 0) != string::npos )			{ return ("down"); }
			else if( Loc = INPUT.find("descend", 0) != string::npos )		{ return ("down"); }

			// Backwards
			else if( Loc = INPUT.find("back", 0) != string::npos )			{ return ("return"); }
			else if( Loc = INPUT.find("return", 0) != string::npos )		{ return ("return"); }
			else if( Loc = INPUT.find("previous", 0) != string::npos )		{ return ("return"); }
			else if( Loc = INPUT.find("backwards", 0) != string::npos )		{ return ("return"); }
			else if( Loc = INPUT.find("south", 0) != string::npos )			{ return ("return"); }
			else if( Loc = INPUT.find("exit", 0) != string::npos )			{ return ("return"); }

			// Left
			else if( Loc = INPUT.find("left", 0) != string::npos )			{ return ("left"); }
			else if( Loc = INPUT.find("west", 0) != string::npos )			{ return ("left"); }

			// Forwards
			else if( Loc = INPUT.find("forward", 0) != string::npos )		{ return ("forward"); }
			else if( Loc = INPUT.find("forwards", 0) != string::npos )		{ return ("forward"); }
			else if( Loc = INPUT.find("straight", 0) != string::npos )		{ return ("forward"); }
			else if( Loc = INPUT.find("ahead", 0) != string::npos )			{ return ("forward"); }
			else if( Loc = INPUT.find("north", 0) != string::npos )			{ return ("forward"); }

			// Right
			else if( Loc = INPUT.find("right", 0) != string::npos )			{ return ("right"); }
			else if( Loc = INPUT.find("east", 0) != string::npos )			{ return ("right"); }

			else return ("");
		}

		else return ("");
	}


And I'm calling my function like so

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
	void Scene_1s1( short PrintTime, short slowPrintTime )
	{
loop:
			
			printf("\n\t:"); getline( cin, p_IN );

			if (p_IN != "") {

				if (srchSTRbasic(p_IN) == "stats")														{ Player::print_pSTATS(); goto loop; }

				if (srchSTRbasic(p_IN) == "return")													{ Scene_1(0, 0); }

				if (srchSTRbasic(p_IN) == "reset")														{ Scene_1(0, 0); }

				if (srchSTRbasic(p_IN) == "forward")										{ Scene_2(printDEFAULT, printALT); }

				if (srchSTRbasic(p_IN) == "left")											{ Scene_1s1(printDEFAULT, printALT); }
			}

			else goto loop;
	}


The issue I'm having is it will work for some words, like when I type "go left" or "return" but whenever I type "left go" or "go back" the program crashes. I've tried a few things but I just can't seem to figure out why it's crashing. Can anybody help?
Last edited on
Topic archived. No new replies allowed.