bookmark - Time Functions Needed

Time Functions Needed

 
 Discussion by khalilov with 9 Replies.
 Last Update: November 14, 2008, 3:12 pm
 
bookmark - Time Functions Needed  
    
free web hosting
 
My class has been asigned with a project which is making a banking system using C language. I searched online and i found that there is a library <time.h> which contains time functions to use in C language. One of them is date(), I tried this:

CODE

#include<conio.h>
#include <time.h>
#include<stdio.h>

void main(){
clock_t start, end;
double elapsed;

start = clock();

end = clock();
elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("%d",start);
getch();}

The program prints 0 onlym how do i print he date?
What i basicly need is a function which reads the current time and stores it, and a function which calculates the number of month/years between 2 dates so that i can calculate loan/banking interests. And what type of variable(structure?) is needed to store the date in it.

I also need a password function, meaning when you write some thing, characters are replaced with starts. Example: password will appear only as ******** on the screen. I have an idea of making a character string and using getch() along with a while loop but iam guessing there is a prebuilt function for this.

Finally i was told that

CODE

printf("\a");

makes a small beaping sound like those old games with DOS, buy iam not getting any sound :/.

Thanks in advance =)

Fri Nov 7, 2008    Reply    New Discussion   


QUOTE (khalilov)

Finally i was told that

CODE

printf("\a");

makes a small beaping sound like those old games with DOS, buy iam not getting any sound :/.
Link: view Post: 130482

Sorry, but I couldn't help but laugh at this. :rolleyes:

My programming lecturer actually spent 10 minutes today recalling anecdotes about people who had basically had beeps playing in a loop...on every computer in the room. Guess what lab session I've got in 25 minutes? :P

Anyway, to the second part of your question (pass as to the first, we haven't got around to time and dates yet, although I'm sure they're on the list somewhere), the code you had there should work fine. I'm assuming it's either more of a problem with the computer itself (lacking a "beep" noise, perhaps?) or it's been turned off/muted.

My suggestion would be to use:

CODE

printf("Beep in 3...2...1...\aBEEP!\n");


As this has other text wrapped around the "beep" (i.e. \a), so in theory if you see all of the other text you should hear the beep as well. If you see the text but don't hear a beep...well, then something's obviously up. You could try asking a lecturer/demonstrator etc. (or whoever is on hand to help your class, if anyone) about it, or try running a few similar tests by having the beep line between various others and seeing if it actually does what else you expect.

Just a few suggestions of mine while I go off to try and have a tamper with them myself. I'll let you know the beep-based results later. :P

Fri Nov 7, 2008    Reply    New Discussion   

CODE

#include<stdio.h>
void main()
{
printf("Beep in 3...2...1...\a\a\a\a\a\a\a\aBEEP!\n");
}

This gave no sound, how do i check fi it is turned off and how do i turn it on?

Fri Nov 7, 2008    Reply    New Discussion   

QUOTE (khalilov)

CODE

#include<stdio.h>
void main()
{
printf("Beep in 3...2...1...\a\a\a\a\a\a\a\aBEEP!\n");
}

This gave no sound, how do i check fi it is turned off and how do i turn it on?
Link: view Post: 130499



Hello friends,

I just want to know the reason why it gave no sound.I am not able to judge this. Please help me regarding this issue.

Sat Nov 8, 2008    Reply    New Discussion   


The guy before me said it gives sound, my friends also told me so. Iam guessing this is a problem with my computer =), maybe a problem with my inner speaker thingies or something :rolleyes:. Did you encounter the same problem?

Sat Nov 8, 2008    Reply    New Discussion   

QUOTE (khalilov)

The guy before me said it gives sound, my friends also told me so. Iam guessing this is a problem with my computer =), maybe a problem with my inner speaker thingies or something :P. Did you encounter the same problem?
Link: view Post: 130533

*grins* Ah, I almost forgot about this thread. The code I gave you above worked like a charm for me, and with a little tweaking we managed to get people playing Mexican waves of beeps around the lab. Certainly made me chuckle a fair bit. :rolleyes:

Mon Nov 10, 2008    Reply    New Discussion   

K i made a password function

CODE

void password(A)
{ char x;
for(i=0;i<6;i++)
{x=getch();
A[i]=x;
printf("*");
}
}

So that part is covered, i still need however the structure for dates :/
if i want to write:

CODE

x=date();

Whats the type of variable x? Iam assuming it has to be structiure, on some sites they had a structure containing minutes/month/years/hours but i didn't understand them.
Is there a function to just get a year or a month or hour? i can make my own date function if i get those. If they exist what are they and in what libraries can i find them?

Thu Nov 13, 2008    Reply    New Discussion   

If you're using C language, then I never myself ever needed to get the current time, but I think you should look into time.h and what does it do on C or find something on google, personally I found this example, I did not try it myself, but I think it should work:

CODE

#include <stdio.h>
#include <time.h>
int main(void)
{
time_t t;
struct tm tstruct;
t = time(0);
tstruct = *localtime(&t);
printf("The time from ctime is %s", ctime(&t));
printf("The time from asctime is %s", asctime(&tstruct));
tstruct.tm_min += 6;
t = mktime(&tstruct);
printf("In 6 minutes,\n");
printf("The time from ctime will be %s", ctime(&t));
printf("The time from asctime will be %s", asctime(&tstruct));
return 0;

}


The output should look something like this:

The time from ctime is Thu May 31 04:52:06 2007
The time from asctime is Thu May 31 04:52:06 2007
In 6 minutes,
The time from ctime will be Thu May 31 04:58:06 2007
The time from asctime will be Thu May 31 04:58:06 2007


So try it :rolleyes:

Fri Nov 14, 2008    Reply    New Discussion   

Thx it works :rolleyes:, but can someone give me some details:P?
whats 'struct tm' is it a predefined structure in the library or something?
Also what are ctime and astime?
finally i only need month/years, whats the function for those O_O

Edit:

CODE

tstruct.tm_min += 6;

Oh thats the minutes, iam assuming

I did

CODE

tstruct.tm_mon += 6;

And it increased 6 month

CODE

tstruct.tm_year += 6;

That increased the years, k thx alot m8.
Can someone post the detailed structure of tm?

Fri Nov 14, 2008    Reply    New Discussion   

Why not search for some references of time.h header on soem search engine?

http://www.cppreference.com/wiki/c/date/start

also look at this site:

http://www.geocities.com/learnprogramming123/Cheader15.htm

Fri Nov 14, 2008    Reply    New Discussion   

Quickly Post to Time Functions Needed  w/o signup Share Info about Time Functions Needed  using Facebook, Twitter etc. email your friend about Time Functions Needed Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

String Library Functions A few questions  String Library Functions A few questions (4) (4) Sleep Function Not Working   Sleep Function Not Working