Jump to content
xisto Community
Sign in to follow this  
khalilov

Time Functions Needed

Recommended Posts

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:

#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
printf("\a");
makes a small beaping sound like those old games with DOS, buy iam not getting any sound :/.

Thanks in advance =)

Share this post


Link to post
Share on other sites

Finally i was told that

printf("\a");
makes a small beaping sound like those old games with DOS, buy iam not getting any sound :/.
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:

 

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

Share this post


Link to post
Share on other sites
#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?

Share this post


Link to post
Share on other sites

#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?

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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?

*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:

Share this post


Link to post
Share on other sites

K i made a password function

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:
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?

Share this post


Link to post
Share on other sites

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:

 

#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:

Share this post


Link to post
Share on other sites

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:

tstruct.tm_min += 6;
Oh thats the minutes, iam assuming

I did
tstruct.tm_mon += 6;
And it increased 6 month

tstruct.tm_year += 6;
That increased the years, k thx alot m8.
Can someone post the detailed structure of tm?
Edited by khalilov (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.