Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- const char *ziffern[] = { "null", "eins", "zwei", "drei", "vier", "fünf",
- "sechs", "sieben", "acht", "neun" };
- const char *zehner[] = { "zwanzig", "dreig", "vierzig", "fünfzig", "sechzig",
- "siebzig", "achtzig", "neunzig" };
- const char *sonder[] = { "zehn", "elf", "zwölf", "dreizehn", "vierzehn",
- "fünfzehn", "sechzehn", "siebzehn", "achtzehn", "neunzehn" };
- int main(int argc, char *argv[])
- {
- int zahl;
- if (argc == 2)
- zahl = strtol(argv[1], NULL, 10);
- else
- {
- printf("Zahl (zwischen 0 und 99) eingeben: ");
- scanf("%d", &zahl);
- }
- if (zahl < 0 || zahl > 99)
- {
- fprintf(stderr, "Aurhalb Wertebereich!\n");
- return EXIT_FAILURE;
- }
- else if (zahl < 10)
- {
- printf("%s\n", ziffern[zahl]);
- }
- else if (zahl < 20)
- {
- printf("%s\n", sonder[zahl - 10]);
- }
- else
- {
- /* strlen("siebenundf") == 16 */
- char *buf = (char *) malloc(17);
- /* im Falle eines vollen Zehners */
- *buf = '\0';
- if (zahl % 10)
- {
- strcpy(buf, ziffern[zahl % 10]);
- if (zahl % 10 == 1) /* einsundzwanzig -> einundzwanzig */
- buf[strlen(buf) - 1] = '\0';
- strcat(buf, "und");
- }
- strcat(buf, zehner[zahl / 10 - 2]);
- printf("%s\n", buf);
- free(buf);
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment