difftime: strptime für konvertieren von string in Zeitformat
-
Hallo,
ich bin silicon, mein erstes post hier.
seit tagen versuche ich über difftime die differenz von 2 zeiten auszuwerten, die als STRING schon vorhanden sind. (Über Sql_select etc. andere Geschichte).Ich versuche diese Strings im Format von z.B 02.09.2003 in das benötigte zeitformat für difftime umzuwandeln.
das ganze spielt sich in folgender funktion ab (typ ist jetzt erstmal uninteressant)
[code]
int validate_date (char *datum, int typ)
{
char *s;
struct tm *sysdate,*carddate;
int day;s = select_sysdate (30); /*funktioniert, kommt aus nem select woanders her*
strptime( datum, "%m.%d.%Y", &carddate );
strptime( s, "%m.%d.%Y", &sysdate );
day = difftime( carddate, sysdate);
return day;
}Mag sein das int Day als Return nicht richtig ist, aber da kommt keine Fehlermeldung.
validate.c: In function
validate_date': validate.c:213: warning: assignment from incompatible pointer type validate.c:214: warning: passing arg 3 of
strptime' from incompatible pointer type
validate.c:216: warning: passing arg 3 ofstrptime' from incompatible pointer type validate.c:218: warning: passing arg 1 of
difftime' makes integer from pointer without a cast
validate.c:218: warning: passing arg 2 of `difftime' makes integer from pointer without a castIst meine bisherige Fehlermeldung.
Sorry, ich spreche noramleweise nicht C und tu mir momentan etwas schwer...
cheers,
silicon
-
Hier mal ein kleines bsp. wie's funkt.
#define PLACEFORTIME 100 /* MAX space for timeString */ #define NULLBYTE 1 void ShowTime(void) { char *currentTime = NULL; struct tm *tm = NULL; time_t when = 0; /*------------------------------------------------------------------------*/ setlocale(LC_ALL, ""); /* For different languages */ time(&when); tm = localtime(&when); currentTime = calloc(PLACEFORTIME + NULLBYTE, sizeof(char)); strftime(currentTime, PLACEFORTIME, "%a %b %e %H:%M:%S %Z %Y", tm); /* -1 for 0 to begin at the top without any space */ printf(Time = "%s", currentTime); free(currentTime); return; }