Interactive text file

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2004
Posts: 353
Reputation: Asif_NSU is on a distinguished road 
Solved Threads: 3
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Interactive text file

 
1
  #1
Mar 16th, 2005
I want to make a program that will start off by opening a text file(blank). The user will put an expression in the file and as he hits the enter(enters a newline character) the result will be shown in the next line of the same open file. Itz almost like replacing the console with a text file. The way mathematica and maple evaluates itz inputs. Is it possible without too much hassle?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,593
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 710
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Interactive text file

 
0
  #2
Mar 16th, 2005
Is there any reason this has to be an interactive file rather than an interactive terminal session that writes to a file periodically?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 353
Reputation: Asif_NSU is on a distinguished road 
Solved Threads: 3
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Re: Interactive text file

 
0
  #3
Mar 17th, 2005
There is actually no reason. The program i have writes to a file periodically. But i was thinking if it could be done, just for fun!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,593
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 710
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Interactive text file

 
0
  #4
Mar 17th, 2005
It's possible, but not practical since on the surface an interactive terminal session has identical functionality and is considerably faster because an interactive file constantly reads from and writes to a slow physical device.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 353
Reputation: Asif_NSU is on a distinguished road 
Solved Threads: 3
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Re: Interactive text file

 
0
  #5
Mar 18th, 2005
hmmm, I undestand. But even then i would like to try that out, provided that someone helps me along the way. The first major problem is to check for the input as the user is typing on the notepad, is it even possible?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,593
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 710
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Interactive text file

 
0
  #6
Mar 18th, 2005
Yes, do research on kbhit. You should find out quickly whether your implementation supports it or not, and how to write your own if it doesn't.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 353
Reputation: Asif_NSU is on a distinguished road 
Solved Threads: 3
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Re: Interactive text file

 
0
  #7
Mar 18th, 2005
I used kbhit() before as i made some small games. I used it inside game loops when u need to read the input only when kbhit() returns a nonzero value(i.e there's been a keyboard hit). I dont know if it can help us with the interactive file thingy. Atleast the following piece of code does not.
  1. #include<conio.h>
  2. #include<iostream>
  3. #include<fstream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. ofstream out("out.txt");
  10. out.close();
  11. system("out.txt");
  12. char ch;
  13. while(true)
  14. {
  15. if(kbhit())
  16. {
  17. ch = getchar();
  18. cout<<ch;
  19. }
  20. }
  21.  
  22. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,593
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 710
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Interactive text file

 
0
  #8
Mar 18th, 2005
Whether it works or not really depends on what you want it to do. What were you expecting?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 353
Reputation: Asif_NSU is on a distinguished road 
Solved Threads: 3
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Re: Interactive text file

 
0
  #9
Mar 19th, 2005
The program opens a blank text file as it starts. The user writes something on that file. I want to know what the user is typing on that textfile. Since i havent done anything like this before, i dont know what to expect from kbhit() in this regard. Maybe a function that can globally read keyboard inputs is necessary in this case, not something that only works when the console is active. I am not sure kbhit() or getchar() will do that job for me.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,593
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 710
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Interactive text file

 
0
  #10
Mar 19th, 2005
Think getch instead of kbhit. An interactive file isn't a file you write directly to with the keyboard. An interactive file is a file that is saved with every change made. You use the console as the middleman between the keyboard and file, but every character you enter is written straight away.

The only difference between, say, vanilla Notepad and Notepad with an interactive file is that vanilla Notepad only saves when you tell it to. Notepad with an interactive file would save constantly so that if power is interrupted and you have to reboot, you don't lose any of your work.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC