C/C++ :: Save The Current Date And Time Into A Char Array?
Jan 14, 2015
I am trying to use to save the current date and time into a char array using this code:
char current_time(char *date){
time_t result = time(NULL);
date = ctime(&result);
return *date;
}
main{
[Code]...
now when I output the date char array into a txt file I only get gibberish.
View 6 Replies
ADVERTISEMENT
Dec 30, 2014
I am doing a school project. The project basically is that it records the in and out time of an employee(of an particular company).The employee while checking in or out should enter a unique key generated specially for him so that no one else can check in and out for him.Then referring to the employees position( A worker or a manager or something like that) his total working time each day , for a week and a month is calculated. The company starts at 8 am and ends at 5 pm for 1st shift and for second shift from 3.30 pm to 2.30 am. Plus Saturday and Sunday off. Then after a month the program refers to the working time date stored in a file and calculates his pay(For workers its per hour salary and for managers it aint).
If an employee is consistently late the details are forwarded to the HR account( so that necessary steps are taken).This will support the company log the details of their employees duty time plus give enough detail to take action if someones always late. I'm doing this as a school project and it needn't be of enterprise class and all.. But i want the coding to perform as it should. Also i'm forced to use the old Turbo C++. Now i'm struck in the place where the time of the employees in and out time is logged. This coding does the work
Code:
void main( ) {
clrscr();
char dateStr [9],timeStr [9];
_strdate( dateStr);
cout<<" The current date is "<<dateStr<<'
[Code] ....
I think the second one is better as it not only gives me date but also gives me the day so i can check easily for the weekends. So, how these time functions work.
View 1 Replies
View Related
Feb 16, 2013
i need to display the current time and date in my program and use variable to store each of the time values like
a = 10
b = 29
c = 31
printf(``%d : %d : %d``, a,b,c);
which then give the output as - 10:29:31
How to save the time in variables in C....
i am using C in windows 7 and my complier is Bloodshed Dev C++
View 7 Replies
View Related
Dec 12, 2014
I need to add the current date to the end of a string but I only need to add the day and not the year or month.
Put the code This is what i have
char date[9];
_strdate(date);
cout << date << endl;
View 1 Replies
View Related
Sep 26, 2014
How can i assign current date as integer ?
for example:
today's date 26 Sep 2014 on a computer
i try to make as below
int day=26
int moth=9
int year=2014
I also research i think i will use time.h library surely
View 3 Replies
View Related
Feb 2, 2013
i have a list of date format 1-12-2011 that i get from a txt file.
char date[30];
fstream fin("date.txt");
fin >> date;
how do i split the date array to 3 array of char day[],char month[] and char year[] for my structure list? using delimiter '-' so i get 1 to day, 12 to month and 2011 to year.
struct date{
string day;
string month;
string year;
}
View 2 Replies
View Related
Oct 10, 2014
When I have loaded a savefile with Serialize, is there some way of telling the name of the currently loaded savefile?
View 2 Replies
View Related
Jan 31, 2015
char num [] = pow(2,4);
how to save whole number to char array ? (16) so that menas char num [] = "16";
but it must be in this form :
char num [] = pow(2,4);
View 3 Replies
View Related
Nov 23, 2012
I have an extra credit project where I'm supposed to calculate an approximate the user's age based on the current date and their birthday. My problem is that I am not getting the proper date and time. C++ keeps giving me some random date. I looked up c++ time format on the internet because this is extra credit and not in my book.
I am currently using dev C++ 4.9.9.2. Here is my current code :
// included libraries
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <time.h>
#define cls system("cls")
#define pauseOutput system("pause")
void printM(int x);
void age(int m, int d, int y, int &yearAge, int &monthAge, int &dayAge);
[Code] ....
View 1 Replies
View Related
Sep 27, 2014
I have an assignment in which i must create a program which prompts for user input of current and birth date, which will compare said dates and output if its your birthday or not. I've completed a large portion of it, but cannot figure out how to get the user input of month as an integer such a 2 into February.
#include <iostream>
using namespace std;
class DayOfYear {
public:
void input();
[code]....
View 1 Replies
View Related
Feb 14, 2013
I'm trying to display the AM/PM on my program:
Also is there a way to display the time only instead of the date? How will i change the program to display the time in standard 12 hours, instead of 24 hours?
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
time_t tim;
time(&tim);
cout << ctime(&tim);
}
View 1 Replies
View Related
Jul 19, 2013
i have to write the current time to a file ?how to do it
View 2 Replies
View Related
Aug 22, 2013
Its a code in module of my program, where I need to print current time (HH:MM:SS) at regular intervals.
Code:
#include<time.h>
#include<stdio.h>
//#include<windows.h>
void delay(unsigned int t){ // loop for some delay.
[Code] ....
But when I am running this code I expect this to print difference in time due to delay. But it doesn't enter the delay loop, why ?
View 5 Replies
View Related
Aug 28, 2014
This is what I have:
#include <ctime>
#include <string>
using namespace std;
void date_and_time(string &date, string &time){
time_t current_time;
[Code] ......
Is there a way to make sure that the strings would not contain trailing spaces?
View 1 Replies
View Related
Mar 16, 2012
How to get system Date and Time and display it in the format DD/MM/YYYY ??
View 2 Replies
View Related
Mar 13, 2014
I am trying to create two classes: a Date class and a Time class. The Date class has to have three private data members: day, month and year. The Time class should have two private data members:hour and minute. Each class should have two member functions: a constructor and display. I am lost and my code won't run ....
class Date {
private:
int month, day, year;
public:
Date(int m, int d, int y){
month = m;
day = d;
year = y;
[code]....
View 2 Replies
View Related
Jan 20, 2013
I am writing a C++ program which takes date & time input from the user. This is then parsed into a struct such as:
struct time
{
short year;
short month;
short day;
short hour;
short min;
};
My question is: how can I convert such a struct into a time_t object, which is an unsigned long giving the time as the number of seconds elapsed since the epoch Jan 1st 1970, 00:00, as set out in time.h.
I am wondering if this can be achieved using the standard library, or whether I just need to write a function to perform the appropriate arithmetic.
View 2 Replies
View Related
Feb 1, 2013
How to show only current date not time in webforms in visual studio as for date and time code is
Label1.Text = DateTime.Now.ToString();
What for only date not time
View 3 Replies
View Related
Feb 2, 2013
The first time my application opens up, it should get the local date out of the System and store this in a registry key. But the second time it should get the date stored in that registryKey and compare it to the date right now.And there is where I am stuck, I just don't know how to get the date out of that key and compare it to the date right now.
This is my code:
RegistryKey key1;
private void btnTrial_Click(object sender, EventArgs e) {
DateTime current = DateTime.Now;
key1 = Registry.CurrentUser.OpenSubKey("myKey");
if (key1 == null)
[code]....
at the last "if" statement it should compare the date stored in the key with the DateTime.Now.
View 9 Replies
View Related
Mar 22, 2013
I'm having a problem with my homework. The task is to write a program that will take time and date typed by user, and increase it by 1 minute. I should write 3 functions - first calls second function that updates time and calls third function, if time is 00:00.Time update works, but date update does not.My whole written code:
Code:
#include<stdio.h>
struct DateAndTime {
struct date {
int day;
int month;
int year;
[code]....
I should check if inputs are numbers only, so I tried including isdigit function from ctype.h library, but that didn't work either, after I was trying it for a good hour or so, but I kinda rage quit that...
View 8 Replies
View Related
Nov 20, 2012
i want to create an application which generates popup alerts at the day of event occurs as well as a day before the event will occur in a specific time interval as well.. events are stored in database and they are all date time fields .. so i want to link those fields to create popups ..
View 2 Replies
View Related
Aug 18, 2014
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.IO.Ports;
[Code] ....
How to pick date / time when serial port starts reading , and also when reading stops ?
View 2 Replies
View Related
Dec 29, 2013
lets say I have a char array with four elements but only one char is used, does it write four elements or just one?
View 3 Replies
View Related
Dec 9, 2013
I have a pointer to an Address is there a way to save that address value (not the content but the actual address) into a char ?
View 5 Replies
View Related
Aug 2, 2013
I am trying to convert char to time and I found the following code. But it gives me a -1 on "converted" instead of time.
#include <stdio.h>
#include <time.h>
#include <iostream>
using namespace std;
[Code].....
View 7 Replies
View Related
Mar 28, 2014
I would like to have a program with a 5 mb string embedded in it kind of like this:
Code:
const char *c;
c = (const char*)"BEGIN_STRING_HERE, (5 MB of arbitrary values here)";
Is it possible to generate this string at compile time? Maybe with a macro? I'm trying to avoid a source file with a 5 mb string in it.
View 3 Replies
View Related