Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

ProLog Program to read list of strings and numbers and copy in database having having string length equal to number using files

Posted By: Milind Mishra     Category: Artificial Intelligence     Views: 3198

Complete prolog program to read a list of strings. Then read a no. All the strings having the length as the same number are to be copied to the database using files..

Code for ProLog Program to read list of strings and numbers and copy in database having having string length equal to number using files in Artificial Intelligence

%trace
domains
    file = input;output
predicates
    start
    readline
    %comp(string)
    search(integer)
    repeat
    end
    

goal
    clearwindow,
    makewindow(1,7,20,"My Window",0,0,25,80),
    start,
    end.
clauses
    start:-
        openread(input,"Q3I.TXT"),
        readdevice(input),
        readline,!,
        
        write("\n\nEnter the no::"),
        readdevice(keyboard),
        readint(No),
        readdevice(input),
        filepos(input,0,0),
        search(No).
                    
    readline:-
        not(eof(input)),
        readln(Line),
        str_len(Line,Len),
        nl,write(Line,"  ",Len),
        readline.
    readline.
    repeat.
        repeat:-
            repeat.
    search(No):-
        repeat,
        readln(Line),
        str_len(Line,Len),
        No=Len,
        openwrite(output,"Q3O.TXT"),
        writedevice(output),
        write(Line,"\n"),
        closefile(output).
    end:-
        write("\n\nplease check output in file Q3O.TXT").

Input file:

¦my name is hiral                                                         ¦
¦my brohter name is ravi  
¦my sister name is hemina                                                   ¦
¦i love my family  


Output

+-----------------------------------My Window----------------------------------+
¦                                                                              ¦
¦my name is hiral  16                                                          ¦
¦my brohter name is ravi  23                                                   ¦
¦my sister name is hemina  24                                                  ¦
¦i love my family  16                                                          ¦
¦                                                                              ¦
¦Enter the no::24                                                              ¦

 please check output in file Q3O.TXT


Output file:
my sister name is hemina
  
Share: 



Milind Mishra
Milind Mishra author of ProLog Program to read list of strings and numbers and copy in database having having string length equal to number using files is from India.
 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in Artificial Intelligence:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!