#include #include #include #include #include #include #include int main(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "Usage: %s traitement\n", argv[0]); exit(EXIT_FAILURE); } setlocale(LC_CTYPE, ""); wctype_t code = wctype(argv[1]); if (code == 0) { fprintf(stderr, "%s: \"%s\": type inconnu du paramétrage local\n", argv[0], argv[1]); exit(EXIT_FAILURE); } while (true) { wprintf(L"Entrer une chaîne : "); char chaine_lue[1024]; const char *p_chaine_lue = fgets(chaine_lue, sizeof chaine_lue, stdin); if (p_chaine_lue == NULL) break; mbstate_t etat; memset(&etat, 0, sizeof etat); size_t nc = strlen(chaine_lue); wchar_t chaine_cl[nc]; size_t ncl = mbsrtowcs(chaine_cl, &p_chaine_lue, nc, &etat); if (ncl == (size_t) -1) { fprintf(stderr, "Chaîne incorrecte\n"); continue; } for (unsigned i = 0; i < nc; i++) { wchar_t c = chaine_cl[i]; if (c == L'\0') break; if (iswctype(c, code)) wprintf(L"(%c)", c); else putwchar(c); } putwchar(L'\n'); } putwchar(L'\n'); return EXIT_SUCCESS; }