1

How can I change a string input to integer- for example-

read_line_to_codes(user_input,L),
atom_codes(C,L).

In this C is storing a string.Suppose the user entered 18.So I want to use this 18 as an integer so that I can use operations like >= with C.Is this possible in Prolog?

false
  • 10,264
  • 13
  • 101
  • 209
  • Possible duplicate of [Prolog: how to convert string to integer?](https://stackoverflow.com/questions/6782007/prolog-how-to-convert-string-to-integer) – Anderson Green Feb 22 '18 at 03:12

2 Answers2

0

Prolog datatypes don't include 'strings'. SWI-prolog added it recently, but you can stay on ISO safety lane with number_codes

CapelliC
  • 59,646
  • 5
  • 47
  • 90
-1

You can forcefully assigned an int datatype to the user input, you are letting the JVM know that you know what you are doing and this will let the program compile in case if the int data type is smaller than the user input string size. Here is an example code to help you.

public class stringToInt{

  public static void main(String []args){

    string C = 18; //User input, make sure to use the scanner class to get the user input value
    int int_C = (int) C;

    /**Your new value is now in int datatype and you can go ahead and use int_C for your arithmetic 
            opreation **/
  }

}
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
Onyia Okey
  • 37
  • 2