Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to read a file and display each of its line one by one and lines chosen by user should go to an output file

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

Prolog program to read a file and display each of its line one by one and lines chosen by user should go to an output file.

Code for Prolog program to read a file and display each of its line one by one and lines chosen by user should go to an output file in Artificial Intelligence

domains
    file = xinput
predicates
    start
    reading(integer)
    searching(integer,integer)
goal
    clearwindow,
    start.
clauses
    start:-
        openread(xinput,"data.txt"),
        readdevice(xinput),
        reading(1).

    reading(LineNo):-
        not(eof(xinput)),
        readln(Line),
        write(LineNo," ",Line),nl,
        LL = LineNo + 1,
        reading(LL).

    reading(_):-
        write("\nEnter Line No = "),
        readdevice(keyboard),
        readint(LineNo),
        filepos(xinput,0,0),
        readdevice(xinput),
        searching(LineNo,1).
        
    searching(LineNo,Num):-
        not(eof(xinput)),
        LineNo <> Num,
        readln(Line),
        NN = Num + 1,
        searching(LineNo,NN).
        
    searching(LineNo,Num):-
        not(eof(xinput)),
        readln(Line),
        closefile(xinput),
        openwrite(xinput,"Outputq6.txt"),
        writedevice(xinput),
        write(Line),nl,
        closefile(xinput),
        write("See file outputq6.txt").
        
    searching(LineNo,Num):-
        write("Enter line no. is outof file"),nl.
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to read a file and display each of its line one by one and lines chosen by user should go to an output file 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!