• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with displaying the time  RSS feed

 
Aron Silvester
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WHAT IT DOES: The application reads in the first line of standard input. For each line of input, if the user enters exit, the application terminates; otherwise, the application interprets the line as a name of a text file. The application creates or recreates this file and writes to it two lines of output, the name of the file and the current date and time. The application then closes the file, reopens it for reading, and writes its content to standard output. The application writes to standard output the name of the file as well as the date and time.

MY PROBLEM: Everything works perfectly but when it’s time to print out the output (filename and time), the seconds in time is the same for all. In this example the seconds is always 33 seconds but I waited at least 3 seconds before I entered each filename.

AN EXAMPLE OUTPUT:
Enter a filename of type 'exit' to quit: essay.txt
Enter a filename of type 'exit' to quit: math.txt
Enter a filename of type 'exit' to quit: english.txt
Enter a filename of type 'exit' to quit: CSCI.txt
Enter a filename of type 'exit' to quit: exit

[essay.txt]
1: essay.txt
2: Sat Sep 13 14:23:33 HST 2014

[math.txt]
1: math.txt
2: Sat Sep 13 14:23:33 HST 2014

[english.txt]
1: english.txt
2: Sat Sep 13 14:23:33 HST 2014

[CSCI.txt]
1: CSCI.txt
2: Sat Sep 13 14:23:33 HST 2014

THE SOURCE CODE:

 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think about what the variable cal refers to. It refers to a point in time which is never changed by your program, it is set once. Hence why the date and time is the same in all files.

After you have waited 3 seconds to enter a new filename, set cal to the current time once again.
 
Aron Silvester
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I go about setting cal to the current time again?
 
Aron Silvester
Ranch Hand
Posts: 63
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
never mind i got it... THANK YOU SO MUCH!!!
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what was the solution, please?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!