Domains
stringList = string*
Predicates
reading
startup(integer,stringList)
comparsion(stringList,string)
compareString(string,string)
compareChar(char,string)
Clauses
startup(0,List):-
write("Enter one more string = "),
readln(Str),
comparsion(List,Str).
startup(Number,StringList):-
write("Enter String = "),
readln(Name),
Newlist = [Name | StringList],
TempNumber = Number - 1,
startup(TempNumber,Newlist).
comparsion(StringList,Str):-
StringList = [Head | Tail],
str_len(Str,Lenstr),
str_len(Head,LenHead),
Lenstr = LenHead,
compareString(Str,Head),
write(Head," Which Is Similar Character As ",Str),nl.
comparsion(StringList,Str):-
StringList = [Head | Tail],
comparsion(Tail,Str).
comparsion(StringList,Str):-
write("No String Found In List Simillar To ",Str),nl.
compareString(Str1,Str2):-
Str1 <> "",
frontchar(Str1,Char1,Rest1),
compareChar(Char1,Str2),
comparestring(Rest1,Str2).
compareString(Str1,Str2):-
Str1 = "".
compareString(Str1,Str2):-
fail.
comparechar(Char1,Str2):-
frontchar(Str2,Char2,Rest2),
Char1 <> Char2,
Rest2 <> "",
compareChar(Char1,Rest2).
comparechar(Char1,Str2):-
frontchar(Str2,Char2,Rest2),
Char1 = Char2.
comp_char(Char1,Str2):-
fail.
reading:-
NumRead = 10,
startup(NumRead,[]).
Goal
clearwindow,
makewindow(1,2,3,"String Operations",0,0,25,80),
reading.
Output :-->
+-------------------------------String Operations------------------------------+
¦Enter String = mayankmodi ¦
¦Enter String = rahul khanna ¦
¦Enter String = rahul patel ¦
¦Enter String = mr.bajaj ¦
¦Enter String = rahul mishara ¦
¦Enter String = idom knayam ¦
¦Enter String = hello ¦
¦Enter String = good morning ¦
¦Enter String = good night ¦
¦Enter String = good ¦
¦Enter one more string = aamynk idom ¦
¦idom knayam Which Is Similar Character As aamynk idom ¦
¦ ¦
¦Press the SPACE bar ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
+------------------------------------------------------------------------------+