Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. (solved) strange thing_one digit missing when using %d for standard output [modified]

(solved) strange thing_one digit missing when using %d for standard output [modified]

Scheduled Pinned Locked Moved Managed C++/CLI
questioncsshelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bloodwinner
    wrote on last edited by
    #1

    I am recording to current time, and compare with the old time which stored in a file. but here t4 is always one digit less. for example, when I check file end.txt and start.txt, t4 is 22284, and t3 is 21975, no problem. but when I calculate and output differ, it shows 2228-21975=-19747. t4 is wrong! what is the problem here? int differ=0; // int old_time=0; int t3=0; int t4=0; time_t t1,t2; FILE * pFile; (void) time(&t2); // record the current time t4=(int)t2; pFile = fopen ("/root/pclinq/end.txt","r+"); fprintf (pFile, "%d",t4); //save the current time to the file fclose (pFile); pFile = fopen ("/root/pclinq/start.txt","r+"); fscanf (pFile, "%d", &t3); //dig out the old time saved fclose (pFile); differ=t4-t3; printf("differ is %d-%d=%d\n",t4,t3,differ); (solved)it turns out the last digit was a remaining one, for example,2228 is the real number recorded this time -- modified at 8:51 Tuesday 17th July, 2007

    L 1 Reply Last reply
    0
    • B bloodwinner

      I am recording to current time, and compare with the old time which stored in a file. but here t4 is always one digit less. for example, when I check file end.txt and start.txt, t4 is 22284, and t3 is 21975, no problem. but when I calculate and output differ, it shows 2228-21975=-19747. t4 is wrong! what is the problem here? int differ=0; // int old_time=0; int t3=0; int t4=0; time_t t1,t2; FILE * pFile; (void) time(&t2); // record the current time t4=(int)t2; pFile = fopen ("/root/pclinq/end.txt","r+"); fprintf (pFile, "%d",t4); //save the current time to the file fclose (pFile); pFile = fopen ("/root/pclinq/start.txt","r+"); fscanf (pFile, "%d", &t3); //dig out the old time saved fclose (pFile); differ=t4-t3; printf("differ is %d-%d=%d\n",t4,t3,differ); (solved)it turns out the last digit was a remaining one, for example,2228 is the real number recorded this time -- modified at 8:51 Tuesday 17th July, 2007

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      bloodwinner wrote:

      (solved)it turns out the last digit was a remaining one, for example,2228 is the real number recorded this time

      and I guess the more appropriate open mode for writing a file is "w+" ... :)

      Luc Pattyn


      try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups