isdigit function problem

Hello, I have a program, where isdigit() function is used to check, if the character in char array is number. But in my program this function doesn't work properly. Here is my program.

if (isdigit(getRequest[5]) == 1)
	{
		room_num = getRequest[5] - '0';
		Serial.print("room_num = ");
		Serial.println(room_num, DEC);
		Serial.print("getRequest[8] = ");
		Serial.println(getRequest[8] - '0', DEC);
		if (getRequest[7] == 't')
		{
			if (isdigit(getRequest[8] == 1))          //here it returns 0, but should return 1
			{
				Serial.println("getRequest[0] is DIGIT");
				temp_num = getRequest[8] - '0';
				Serial.print("temp_num = ");
				Serial.println(temp_num, DEC);
			}
                  }

Thank you for help.

I solved it :slight_smile: if (isdigit(getRequest[8] == 1)) should be if (isdigit(getRequest[8])==1) Bad backets

Both are arguably wrong, you should not assume that isDigit() returns 1 for true, you can
only assume the result is 0 for false. Just use:

  if (isDigit (getRequest [8]))

Many things in C do pass 1 for true, but everything that uses a boolean value(*) only
assumes false is represented by a zero value, so do likewise.

(*) if, while, !, #if