C# code to make the character stop

make the character stop without button press

That depends on how you move your character. Do you use a rigidbody or a character controller or transform translate? Also it would be good if you posted your movement code.

This is the movement code of the character:

CharacterController controller = GetComponent();
transform.Rotate(0, Input.GetAxis (“Horizontal”) * rotateSpeed, 0);
Vector3 forward = transform.TransformDirection(Vector3.forward);
transform.position += transform.right * speed * Time.deltaTime;
controller.SimpleMove(forward);

Assuming the code you posted is called within Update() you are always moving the character to his right by setting his position and move him forward through the SimpleMove() function. The character naturally wont stop moving because the input plays no role in the calculation of these movements.
You should ony use one method to mvoe the character. Since you have a character controller you should only use Move() or SimpleMove() rather than setting the transforms position.
If you want to incorporate e.g. the up/down button input you can multiply the vector forward with ‘Input.GetAxis(“Vertical”)’.