C programming/scanf

From Teknologisk videncenter
< C programming
Revision as of 09:59, 4 October 2017 by Heth (talk | contribs) (Created page with "<source lang=c> #include <stdio.h> char txt[] = "4/10/2017 10:59:18"; struct TimeStruct { // Declare structure TimeStruct int sec; // seconds...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#include <stdio.h>


char txt[] = "4/10/2017 10:59:18";

struct TimeStruct {     // Declare structure TimeStruct
        int     sec;        // seconds              00 to 59
        int     min;        // minutes              00 to 59
        int     hour;       // hours                00 to 23
        int     mday;       // day of the month     1 to 31
        int     mon;        // month                1 to 12
        int     year;       // year                 1970 to 2106
};
int main( void ) {
        struct TimeStruct t;
        int result;
        result = sscanf(txt,"%i/%i/%i %i:%i:%i",
                &t.mday,
                &t.mon,
                &t.year,
                &t.hour,
                &t.min,
                &t.sec);
        printf("Returnerer %i\n",result);

        printf(" Det er %i dag i måneden %i, året er %i og klokken er %i sekunder og %i minutter over %i\n",
                t.mday,
                t.mon,
                t.year,
                t.sec,
                t.min,
                t.hour);
        return(0);

}