khalilov 0 Report post Posted November 7, 2008 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
Mordent 0 Report post Posted November 7, 2008 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. 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? 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. Share this post Link to post Share on other sites
khalilov 0 Report post Posted November 7, 2008 #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
Jasmine88 0 Report post Posted November 8, 2008 #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
khalilov 0 Report post Posted November 8, 2008 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 . Did you encounter the same problem? Share this post Link to post Share on other sites
Mordent 0 Report post Posted November 10, 2008 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 . 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. Share this post Link to post Share on other sites
khalilov 0 Report post Posted November 13, 2008 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
Quatrux 4 Report post Posted November 14, 2008 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 Share this post Link to post Share on other sites
khalilov 0 Report post Posted November 14, 2008 (edited) Thx it works , 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_OEdit: tstruct.tm_min += 6;Oh thats the minutes, iam assuming I didtstruct.tm_mon += 6;And it increased 6 monthtstruct.tm_year += 6;That increased the years, k thx alot m8. Can someone post the detailed structure of tm? Edited November 14, 2008 by khalilov (see edit history) Share this post Link to post Share on other sites
Quatrux 4 Report post Posted November 14, 2008 Why not search for some references of time.h header on soem search engine?http://en.cppreference.com/w/cpp/chrono/calso look at this site:https://smallbusiness.yahoo.com/ Share this post Link to post Share on other sites