]> git.sur5r.net Git - c128-kasse/blob - src/general.c
create src/images/include-folders to clean up the directory
[c128-kasse] / src / general.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <conio.h>
5
6 #include "general.h"
7
8 /*
9  * Liest (maximal 31) Zeichen ein, bis Enter gedrückt wird.
10  * Vorsicht: Es wird ein statischer Buffer benutzt, sodass man
11  * das Ergebnis via strdup() retten muss, bevor man get_input()
12  * erneut aufruft
13  *
14  */
15 char *get_input() {
16         BYTE i = 0;
17         static char output[32];
18         BYTE c;
19         memset(output, '\0', 32);
20         while (1) {
21                 if (i == 31)
22                         break;
23                 c = getchar();
24                 if (c == 13)
25                         break;
26                 else output[i++] = c;
27         }
28         return output;
29 }
30
31 char *format_euro(char *s, int maxlen, int cent){
32         int tmp = cent;
33         int len = strlen(",EUR");
34         while ((tmp /= 10) > 0)
35                 ++len;
36         if (len >= maxlen)
37                 return NULL;
38         sprintf(s, "%d,%dEUR", cent / 100, cent % 100);
39         return s;
40 }
41
42 void c128_perror(BYTE c, char *msg) {
43         cprintf("\r\nError (Code %d) while: %s\r\nOS Error = %d\r\n", c, msg, _oserror);
44 }