// crt_locale.c /* Sets the current locale to "Germany" using the * setlocale function and demonstrates its effect on the strftime * function. */ #include #include #include int main(void) { time_t ltime; struct tm *thetime; unsigned char str[100]; setlocale(LC_ALL, "German"); time (<ime); thetime = gmtime(<ime); /* %#x is the long date representation, appropriate to * the current locale */ if (!strftime((char *)str, 100, "%#x", (const struct tm *)thetime)) printf("strftime failed!\n"); else printf("In German locale, strftime returns '%s'\n", str); /* portuguese-brazil */ setlocale(LC_ALL, "portuguese-brazil"); time (<ime); thetime = gmtime(<ime); /* %#x is the long date representation, appropriate to * the current locale */ if (!strftime((char *)str, 100, "%#x", (const struct tm *)thetime)) printf("strftime failed!\n"); else printf("No Brasil locale, strftime retorna '%s'\n", str); /* Set the locale back to the default environment */ setlocale(LC_ALL, "C"); time (<ime); thetime = gmtime(<ime); if (!strftime((char *)str, 100, "%#x", (const struct tm *)thetime)) printf("strftime failed!\n"); else printf("In 'C' locale, strftime returns '%s'\n", str); }