]> git.sur5r.net Git - c128-kasse/blob - general.c
03bc576107e548adb5fc980a811fecaba61fbb37
[c128-kasse] / general.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 #include "general.h"
6
7 /*
8  * Liest (maximal 31) Zeichen ein, bis Enter gedrückt wird. Der zurückgegebene 
9  * char-pointer muss anschließend ge-free()d werden!
10  *
11  */
12 char *get_input() {
13         BYTE i = 0;
14         char *output = malloc(32 * sizeof(char));
15         BYTE c;
16         if (output == NULL) {
17                 perror("malloc()");
18                 exit(1);
19         }
20         memset(output, '\0', 32);
21         while (1) {
22                 if (i == 31)
23                         break;
24                 c = getchar();
25                 if (c == 13)
26                         break;
27                 else output[i++] = c;
28         }
29         return output;
30 }
31
32 char * format_euro(char * s, int maxlen, int cent){
33         int tmp = cent;
34         int len = 5; // 1 char at least + 4 (== strlen(",EUR"))
35         while ((tmp/=10) > 0)
36                 len++;
37         if (len>maxlen)
38                 return NULL;
39         sprintf(s, "%d,%dEUR", cent/100, cent%100);
40         return s;
41 }
42
43 void c128_perror(BYTE c, char *msg) {
44         printf("\nError (Code %d) while: %s\nOS Error = %s\n", c, msg, _oserror);
45 }