Domains
stringlist = string*
Predicates
startup
reading(stringlist)
findClosestString(integer,stringlist,stringlist,stringlist)
Clauses
startup:-
write("\nEnter Any String = "),
readln(Str),
OldList = [Str],
reading(OldList).
reading(OldList):-
write("\nDo You Want To Enter Another String (y/n) ? : "),
readchar(Ans),
write(Ans),nl,
Ans = 'y',
write("\nEnter Any String = "),
readln(Str),
Newlist = [Str|OldList],nl,
reading(Newlist).
reading(OldList):-
write("\nEnter ANy Positive Number = "),
readint(Number),
findClosestString(Number,OldList,[],Newlist).
findClosestString(_,[],List,_):-
write(List).
findClosestString(Number,Oldlist,List,Newlist):-
Oldlist = [Head | Tail],
str_len(Head,Length),
Number - 1 <= Length,
Number + 1 >= Length,
Newlist = [Head | List],
findClosestString(Number,Tail,Newlist,List2).
findClosestString(Number,Oldlist,List,Newlist):-
Oldlist = [Head | Tail],
Newlist = List,
findClosestString(Number,Tail,Newlist,List2).
Goal
clearwindow,
makewindow(1,2,3,"String Operations",0,0,50,80),
startup.
Output :-->
+-------------------------------String Operations------------------------------+
¦ ¦
¦Enter Any String = Mayank ¦
¦ ¦
¦Do You Want To Enter Another String (y/n) ? : y ¦
¦ ¦
¦Enter Any String = raj ¦
¦ ¦
¦ ¦
¦Do You Want To Enter Another String (y/n) ? : y ¦
¦ ¦
¦Enter Any String = rahul ¦
¦ ¦
¦ ¦
¦Do You Want To Enter Another String (y/n) ? : y ¦
¦ ¦
¦Enter Any String = kesha ¦
¦ ¦
¦ ¦
¦Do You Want To Enter Another String (y/n) ? : y ¦
¦ ¦
¦Enter Any String = shwetambari ¦
¦ ¦
¦ ¦
¦Do You Want To Enter Another String (y/n) ? : y ¦
¦ ¦
¦Enter Any String = anukul ¦
¦ ¦
¦ ¦
¦Do You Want To Enter Another String (y/n) ? : n ¦
¦ ¦
¦Enter ANy Positive Number = 5 ¦
¦["Mayank","rahul","kesha","anukul"] ¦
¦Press the SPACE bar ¦
¦ ¦
+------------------------------------------------------------------------------+