Thread: obtaining boot time in nice format

  1. #1
    Registered User
    Join Date
    Sep 2002

    obtaining boot time in nice format

    Hey all,
    I need to convert the given boot time which is given in the /proc/stat filesystem in seconds to ctime(). Please look at this code and tell me what I am doing wrong. Thank you.
      /* BOOT TIME */
      int boot_time;
      double location_btime;
      thisFile = fopen("/proc/stat", "r");
      while (fgets(Buffer, LB_SIZE + 1, thisFile) != NULL)
        /* while the feof has not been reached, print info line by line */
          if (strstr(Buffer, "btime") != NULL){
            location_btime = ftell(thisFile);
      fseek(thisFile, location_btime - 12, SEEK_SET);
      fscanf(thisFile, "%d\n", &boot_time);
      printf("boot time in sec: %d\n", ctime(&boot_time));

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    ftell() and fseek() deal with a long int, not a double. But instead of all the ftell()/fseek() hocuspocus I think I'd just break out of the fgets() loop and do: boot_time = atol(Buffer+6);
    Last edited by itsme86; 09-15-2004 at 05:09 PM.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    I second that.
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  2. I apologize. Good bye.
    By doubleanti in forum A Brief History of
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM
  3. Is this really true or it's just science fiction?
    By Nutshell in forum A Brief History of
    Replies: 145
    Last Post: 04-09-2002, 06:17 PM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM
  5. relating date....
    By Prakash in forum C Programming
    Replies: 3
    Last Post: 09-19-2001, 09:08 AM