Δημοσιεύτηκε: 21 Ιουν 2011, 12:23
Ορίστε κι ένα προγραμματάκι από εμένα για επεξεργασία της ημερομηνίας.
Το κυρίως πρόγραμμα (main) είναι αυτό εδώ: http://www.gnu.org/s/hello/manual/libc/ ... ample.html
Το κυρίως πρόγραμμα (main) είναι αυτό εδώ: http://www.gnu.org/s/hello/manual/libc/ ... ample.html
- Κώδικας: Επιλογή όλων
#include <stdio.h>
#include <time.h>
#define SIZE 256
char buffer[SIZE];
int xdays(time_t rawtime, int days, char sign)
{
/* Get date after / before X days */
struct tm *timeinfo;
timeinfo = localtime(&rawtime);
if (sign == '+') {
timeinfo->tm_mday = timeinfo->tm_mday + days;
sprintf(buffer, "Date after %d days: ", days);
}
else if (sign == '-') {
timeinfo->tm_mday = timeinfo->tm_mday - days;
sprintf(buffer, "Date before %d days: ", days);
}
mktime(timeinfo);
fputs(buffer, stdout);
strftime(buffer, SIZE, "%A, %B %d %Y.\n", timeinfo);
fputs(buffer, stdout);
return 0;
}
int tomorrow(time_t rawtime)
{
/* Get tomorrow's date */
struct tm *timeinfo;
rawtime = time(NULL);
timeinfo = localtime(&rawtime);
timeinfo->tm_mday = timeinfo->tm_mday + 1;
mktime(timeinfo);
strftime(buffer, SIZE, "Tomorrow will be: %A, %B %d %Y.\n", timeinfo);
fputs(buffer, stdout);
return 0;
}
int curtime(time_t rawtime)
{
struct tm *loctime;
/* Convert it to local time representation. */
loctime = localtime(&rawtime);
/* Print out the date and time in the standard format. */
fputs(asctime(loctime), stdout);
/* Print it out in a nice format. */
strftime(buffer, SIZE, "Today is %A, %B %d %Y.\n", loctime);
fputs(buffer, stdout);
strftime(buffer, SIZE, "The time is %I:%M %p.\n", loctime);
fputs(buffer, stdout);
return 0;
}
int main()
{
time_t rawtime;
rawtime = time(NULL);
curtime(rawtime);
tomorrow(rawtime);
xdays(rawtime, 30, '+');
return 0;
}