RE: [BULK] get minutes of system time as int in c++

  • From: Alex Hall <mehgcap@xxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sat, 07 Jun 2008 23:22:30 -0400

It was correct when I sent it (I copied it directly from the cpp file I am compiling successfully) but my email program, on a braillenote, stripped out any braces that were by themselves on new lines for some reason; I am going to report this bug as soon as I finish this email. If this list supports attachments I can just send my cpp file instead of pasting it. Another email will be coming shortly from me with another code attempt, using my pc instead of my bn this time. Sorry about that; I had no idea it would do that. Of course it will not work with no closing braces. : That last loop is so that the main loop does not repeat, seeing that it is a "beeping minute" many times in that minute. I update min2 but not min, so that as long as min is equal to min2 the loop runs. Once they are not equal, in other words once min2 has a value other than that of min (meaning that the minute has changed), that "idling" loop will exit (min is now less than min2 so the repeat condition is false) and the main "beeping" loop will run again, updating both min and min2 and doing it all over again. The secondary loop is simply there to stop the program from seeing a minute many times and beeping over and over again; it delays until the minute changes, then lets the main loop check to see if it should beep, then the idling loop is hit again and waits for another minute change. Does this make sense? Oh, and I found the exit(0); function to exit the program, so that question about how to exit has been answered.


Have a great day,
Alex

----- Original Message -----
From: "Ken Perry" <whistler@xxxxxxxxxxxxx
To: <programmingblind@xxxxxxxxxxxxx
Date sent: Sat, 7 Jun 2008 19:42:26 -0700
Subject: RE: [BULK]  get minutes of system time as int in c++



I have to agree with Bob. When I said you need to send code so
we can help
the idea was to send working code. This will not compile nor
would it do
anything useful if it did. I was thinking of fixing it for you
but I am not
sure I understand what your trying to do. Do you have a
description of what
this is supposed to do?

I can see that the first part of it you want it to beep on the
hour as many
beeps as there is hours so for example if its 3 it should beep 3
times.  I
also see you want it to beep on the half hour and on the 15
minutes.  I
don't understand at all though what that last While loop is
supposed to do.


If you fix the code to have the correct {} and make it work some
what I can
help more. That or describe what it is supposed to do and I can
probably
write up something that does it.

Ken

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Ken
Perry
Sent: Saturday, June 07, 2008 1:49 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: [BULK] get minutes of system time as int in c++



I will help you out when I get home if no one else does but I
have to go buy
some sheet rock and my wife is driving now grin.

Ken

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex
Hall
Sent: Saturday, June 07, 2008 1:10 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: [BULK] get minutes of system time as int in c++

This is cpp, for windows xp, compiled with the Dev c++ compiler
version
4.9.9.2. Pretend new lines are in the right spot; my email
program forces
returns where I do not want them.  When the
line:
cmd=getch();
is commented out, the program works perfectly, but uncomment it
and the
program will not work. Oddly, pressing b twice will cause it to
work once,
but other than that it will not beep.
Also note that the q and e commands do not work because
system("exit") did not exit the program like I wanted; I am still
looking
for a way of doing this.

Code for beepclock.cpp:

#include <conio.h
#include <iostream
#include <windows.h
#include <stdio.h
#include <time.h
#include <stdlib.h
using namespace std;
int main () {
int end=0;
int min=0;//stores current system minutes int min2=0;//stores
minutes as
well, used to make infinite loop so beeps do not happen
//multiple times for
the same minute int hour=0;//stores current hour bool
beeps=true;//True' is
beeps enabled, 'false' is silence string cmd; cout<<"This program
beeps once
on the quarter hour,"; cout<<"\ntwice on the half, and three
times at
quarter of the hour,\n"; cout<<"all at 488 mhz. Each hour it
beeps as many
times as the hour is at 244mhz.\n"; cout<<"To silence beeps, type
\"s\", and
to reenable them type \"b\".\n"; cout<<"To exit, press either
\"e\" or
\"q\".\n"; while(end==0){//loop not supposed to ever end so
monitoring of
sys clock and beep alerts continue time_t now=time(NULL);//get
current time
in secs from 01-01-70
tm* t =localtime(&now);//ccvert to tm struct for getting minutes
and hofs
later min=t->tm_min;//get minutes from said tm struct
min2=min;//used for
loop at the end of this main loop hour=t->tm_hour;//now get hours
if(hour>12) hour-=12;//set to 12 hour, 1300=1:00
if(hour==0)hour=12;//0000=12 midnight
if(min==0&&beeps){//t is on an hour,
for(int i=0;i<hour;i++){//s beep that hour Beep(244, 500);
Sleep(500);//pause


else{//is it on a 15-minute time?
if(min==15&&beeps){//15 past the hour, beep once Beep(488, 500);

else if(min==30&&beeps){//half past, beep twice Beep(488, 500);
Sleep(500);
Beep(488, 500);

else if(min==45&&beeps){//quarter of, beep 3 times Beep(488,
500);
Sleep(500); Beep(488, 500); Sleep(500); Beep(488, 500);


while(min==min2){//idle in this loop until minute changes time_t
now=time(NULL);//get current time in secs from 01-01-70
tm* t =localtime(&now);//ccvert to tm struct for getting minutes
min2=t->tm_min;//get minutes again to see if this loop should end
//comment
following line and prog runs great, leave it and no beeps.
//I used it thinking that if no <enter> was needed then it would
just wtch
for input, not wait for it like it is seeming to do
cmd=getch();//this loop
is good for input //because it is almost always running, getch
gets char
from kbd w/o <enter if(cmd=="s"){ beeps=false; system("cls");
cout<<"Beeps
disabled, type \"b\" to enable.\n";

else if(cmd=="b"){
beeps=true;
system("cls");
cout<<"Beeps enabled, type \"s\" to disable.\n";


cout<<"test";//to tell me when loop exits, for testing }
cin.get(); return
false;


Have a great day,
Alex

----- Original Message -----
From: "Ken Perry" <whistler@xxxxxxxxxxxxx
To: <programmingblind@xxxxxxxxxxxxx
Date sent: Fri, 6 Jun 2008 23:42:18 -0700
Subject: RE: [BULK]  get minutes of system time as int in c++



I could not really help unless you had an example bit of source
that doesn't
work the way you expect it to.  When your writing lists like this
you should
try to break the problem down into a simple small main that shows
the
problems o we can help fix it.

Ken

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex
Hall
Sent: Friday, June 06, 2008 9:22 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: [BULK] get minutes of system time as int in c++

I will look into that.  Google seems silent on the subject, but I
have
probably not hit on the correct search terms that will uncover
the
information.  Do you know anything about getchar() and
getch()"Getch seems
to react to a character input with no enter key, while getchar
seems more
like cin>>.  I used getch hoping for the results I am looking
for, but,
while I can press letters of commands and have those commands
execute
without me hitting enter, there is still a problem in the
program; the
actual function I want will not run.

Have a great day,
Alex

----- Original Message -----
From: "Ken Perry" <whistler@xxxxxxxxxxxxx
To: <programmingblind@xxxxxxxxxxxxx
Date sent: Fri, 6 Jun 2008 21:08:24 -0700
Subject: RE: [BULK]  get minutes of system time as int in c++



Since your using Devc++ your best bet is probably the select
statement for
making it continue on.  Most of the time people use the select
statement for
socket programs and once you master it you will find making a
multi user
game easier as well.  I just thought I would point you in the
right
direction.

Ken

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex
Hall
Sent: Friday, June 06, 2008 6:08 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: [BULK] get minutes of system time as int in c++

Ok, I have it working, thanks for your help!!! The whole time
thing makes
more sense now.  My only hang-up now (until the next one comes
along, I am
sure) is that I need it to run constantly, which it does, but I
would like
to be able to give commands.
Currently, though, it stops running and waits for my commands,
then executes
them and hits my cin >> and stops again.  Is there some sort of
cin>> that
does not make the system stop to await input?

Have a great day,
Alex

----- Original Message -----
From: "Ken Perry" <whistler@xxxxxxxxxxxxx
To: <programmingblind@xxxxxxxxxxxxx
Date sent: Fri, 6 Jun 2008 16:58:31 -0700
Subject: RE: [BULK]  get minutes of system time as int in c++



Then what you need is the tm structure and a function called
local time.
There is a simple example on this page.

http://www.cplusplus.com/reference/clibrary/ctime/localtime.html

Note they just print the full time in this string but if  you
look in your
time.h file you will find all the tm_day tm_month tm_year fields
that you
can use in the structure tm if you still have trouble just drop
me a line
and I will create another simple program.

A hint is use the tm structure that they pass to the asctime
function but
use it like bla.tm_day etc.


Ken

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex
Hall
Sent: Friday, June 06, 2008 3:23 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: [BULK] get minutes of system time as int in c++

I have read it, but mktime and the others will not work as they
make the
entire string and all I am trying to get out of the deal is the
minutes, not
the entire thing.  I could make minutes out of the seconds like
you did, but
that would be a very large amount of minutes that I could not get
as being
either on the hour or 15, 30, or 45 minutes after the hour.
Similar with
the hour itself; I could not say which hour it is.  Is there a
way of
getting the minutes out of the tm object, defined in the object
definition
as tm_min?

Have a great day,
Alex

----- Original Message -----
From: "Ken Perry" <whistler@xxxxxxxxxxxxx
To: <programmingblind@xxxxxxxxxxxxx
Date sent: Fri, 6 Jun 2008 14:46:34 -0700
Subject: RE: [BULK]  get minutes of system time as int in c++



That is the system clock all I did was subtract the system clock
for when
the program began to the system clock after the loop.  The t1 is
the number
of seconds from that date in 1970 so with that you should be able
to use the
ctime on the page I sent you to get a printable time.  I really
think you
need to read the page I sent you .
-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex
Hall
Sent: Friday, June 06, 2008 2:36 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: [BULK] get minutes of system time as int in c++

Got it.  Is there a way to apply this to tracking the system
clock instead
of the elapsed time of a program?

Have a great day,
Alex

----- Original Message -----
From: "Ken Perry" <whistler@xxxxxxxxxxxxx
To: <programmingblind@xxxxxxxxxxxxx Date sent: Fri, 6 Jun 2008
14:13:13 -0700
Subject: RE: [BULK]  get minutes of system time as int in c++


If you look in time.h you will find that time_t when using dev
c++ is just a
long int.  And what it is, is the amount of seconds since 1970
some time.
If you read this page you will learn more.

http://rabbit.eng.miami.edu/info/functions/time.html

Why I use null is because that gives you the current time.  I
used the
modulus because that gives you the remainder in a division in
this case it
would be 5 seconds.  If you had 70 seconds it would return a
remainder of 10
instead of 5.

Ken


-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex
Hall
Sent: Friday, June 06, 2008 1:44 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: [BULK] get minutes of system time as int in c++

Thanks.  A couple questions:
1.  Exactly what is the time_t object and what can you do with
it?
2.  Why, to get seconds, do you mod by 60 yet minutes you divide
by 60?
3.  Why do you pass null to the time function, and what does that
time
function return?

Have a great day,
Alex

----- Original Message -----
From: "Ken Perry" <whistler@xxxxxxxxxxxxx
To: <programmingblind@xxxxxxxxxxxxx Date sent: Fri, 6 Jun 2008
13:25:37 -0700
Subject: RE: [BULK]  get minutes of system time as int in c++



Ok while I was waiting on your response I wrote this to check the
minutes
and seconds elapsed while running some commands.  Note I did not
use any
special libraries like a Date class that they have in most
compilers.  Here
is the most basic with out using assembler snicker.  It works for
both gcc
and visual studio's c++  Just delete the defined lines depending
on what
your using.


#ifdef VC++_COMPILER
#include <windows.h
#endif
#include <time.h
#include <iostream

using namespace std;

int main(int argc, char* argv[])
{
time_t t1 = time(NULL);

//do some tasks here
for (long  i=0;i<65;i++)
#ifdef GCC
//_sleep(1000);
#endif
#ifdef VC++_COMPILER
Sleep(1000);
#endif

time_t t2 = time(NULL);
int seconds=(t2-t1)%60;
int minutes=(t2-t1)/60;

cout <<"elapsed time = "<<minutes<< " minutes "<< seconds<< "
seconds
"<<endl;

return (0);

}



-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Ken
Perry
Sent: Friday, June 06, 2008 12:58 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: [BULK] get minutes of system time as int in c++



Oh sorry the original mail did not come to me it got junked I got
the
response and that was the one I was replying to.

Now I can tell you how to get system time all the way to the
assembler level
but it helps in knowing what c++ environment your working in
because it
makes a difference for example they have data and time classes in
Microsoft
that is some times easier to use then to actually write the code
yourself.
So tell me what compiler your using and for what operating system
and I will
give you an example.

Ken

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex
Hall
Sent: Friday, June 06, 2008 12:34 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: [BULK] get minutes of system time as int in c++

The example did not have stdlib, and stdio was just the word, no
h.  Thanks.
The question still  stands, though: how can  I get the minutes of
the system
time? Apparently there is a time_t object, but I could not find
much on
that.

Have a great day,
Alex

----- Original Message -----
From: "Ken Perry" <whistler@xxxxxxxxxxxxx
To: <programmingblind@xxxxxxxxxxxxx Date sent: Fri, 6 Jun 2008
12:09:03 -0700
Subject: RE: [BULK]  get minutes of system time as int in c++



You should be able to compile a printf into your c++ program as
long as you
include the header for printf which is stdio and stdlib with the
h
extention.

Ken

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex
Hall
Sent: Friday, June 06, 2008 11:04 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: [BULK] get minutes of system time as int in c++

Yes, just the 34 of 16:34.  The examples used printf() which is,
I believe,
a c function and stopped my program from compiling in cpp.

Have a great day,
Alex

----- Original Message -----
From: "Sean Farrow" <sean.farrow@xxxxxxxxxxxxxxxx
To: <programmingblind@xxxxxxxxxxxxx Date sent: Fri, 6 Jun 2008
18:27:38 +0100
Subject: RE: [BULK]  get minutes of system time as int in c++

Hi Alex:
Plese could you clarify what you want: if the time is 16:34, do
you just
want the 34?
What examples did you fine?
Sean.

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex
Hall
Sent: 06 June 2008 17:50
To: programmingblind@xxxxxxxxxxxxx
Subject: [BULK] get minutes of system time as int in c++
Importance: Low

how could I go about getting the minutes, as an integer, of the
system
time using cpp? I tried to find it, but got what seemed to be
examples
in c not cpp.  Thanks.

Have a great day,
Alex
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind




__________ Information from ESET NOD32 Antivirus, version of
virus
signature database 3164 (20080606) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



__________ Information from ESET NOD32 Antivirus, version of
virus
signature database 3164 (20080606) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: