Guest User

Untitled

a guest
Oct 31st, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. const char *ziffern[] = { "null", "eins", "zwei", "drei", "vier", "fünf",
  6.     "sechs", "sieben", "acht", "neun" };
  7. const char *zehner[] = { "zwanzig", "dreig", "vierzig", "fünfzig", "sechzig",
  8.     "siebzig", "achtzig", "neunzig" };
  9. const char *sonder[] = { "zehn", "elf", "zwölf", "dreizehn", "vierzehn",
  10.     "fünfzehn", "sechzehn", "siebzehn", "achtzehn", "neunzehn" };
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14.     int zahl;
  15.     if (argc == 2)
  16.         zahl = strtol(argv[1], NULL, 10);
  17.     else
  18.     {
  19.         printf("Zahl (zwischen 0 und 99) eingeben: ");
  20.         scanf("%d", &zahl);
  21.     }
  22.     if (zahl < 0 || zahl > 99)
  23.     {
  24.         fprintf(stderr, "Aurhalb Wertebereich!\n");
  25.         return EXIT_FAILURE;
  26.     }
  27.     else if (zahl < 10)
  28.     {
  29.         printf("%s\n", ziffern[zahl]);
  30.     }
  31.     else if (zahl < 20)
  32.     {
  33.         printf("%s\n", sonder[zahl - 10]);
  34.     }
  35.     else
  36.     {
  37.         /* strlen("siebenundf") == 16 */
  38.         char *buf = (char *) malloc(17);
  39.         /* im Falle eines vollen Zehners */
  40.         *buf = '\0';
  41.         if (zahl % 10)
  42.         {
  43.             strcpy(buf, ziffern[zahl % 10]);
  44.             if (zahl % 10 == 1) /* einsundzwanzig -> einundzwanzig */
  45.                 buf[strlen(buf) - 1] = '\0';
  46.             strcat(buf, "und");
  47.         }
  48.         strcat(buf, zehner[zahl / 10 - 2]);
  49.         printf("%s\n", buf);
  50.         free(buf);
  51.     }
  52.    return EXIT_SUCCESS;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment