diff options
| author | nic-gaffney <gaffney_nic@protonmail.com> | 2023-12-05 06:51:38 -0600 |
|---|---|---|
| committer | nic-gaffney <gaffney_nic@protonmail.com> | 2023-12-05 06:51:38 -0600 |
| commit | f655a862106a8a05bc432c2df957979f3fcc399b (patch) | |
| tree | 28134136bdbbaa5dc423403f0985ccf8fb60e861 /std/stdio.c | |
| parent | c748aedbc265fdc7d62768d368161a1f1d88b9a4 (diff) | |
| parent | d767828cee67bae17b811062949653234aa14b28 (diff) | |
| download | sloth-f655a862106a8a05bc432c2df957979f3fcc399b.tar.gz | |
merge
Diffstat (limited to 'std/stdio.c')
| -rw-r--r-- | std/stdio.c | 60 |
1 files changed, 24 insertions, 36 deletions
diff --git a/std/stdio.c b/std/stdio.c index b5f1dd0..e9cefd0 100644 --- a/std/stdio.c +++ b/std/stdio.c @@ -1,48 +1,36 @@ #include <stdio.h> #include <stdlib.h> -char* readln() { - char* str = malloc(128); - scanf("%127s", str); - return str; +char *readln() { + char *str = malloc(128); + fgets(str, 127, stdin); + return str; } -void print(char *str) { - fputs(str, stdout); -} +void print(char *str) { fputs(str, stdout); } -void termpos(int x, int y) { - printf("\x1b[%d;%dH", x, y); -} +void termpos(int x, int y) { printf("\x1b[%d;%dH", x, y); } -void termclear() { - printf("\x1b[2J\x1b[H"); -} +void termclear() { printf("\x1b[2J\x1b[H"); } -void curshide() { - print("\x1b[?25l"); -} +void curshide() { print("\x1b[?25l"); } -void cursshow() { - print("\x1b[?25h"); -} +void cursshow() { print("\x1b[?25h"); } -char* filer(char* path) { - FILE *fptr = fopen(path, "rb"); - char *contents = 0; - - if(fptr == NULL) { - return "File not found"; - } - fseek(fptr, 0, SEEK_END); - long size = ftell(fptr); - fseek(fptr, 0, SEEK_SET); - - contents = malloc(size); - fread(contents, 1, size, fptr); - fclose(fptr); - - return contents; -} +char *filer(char *path) { + FILE *fptr = fopen(path, "rb"); + char *contents = 0; + if (fptr == NULL) { + return "File not found"; + } + fseek(fptr, 0, SEEK_END); + long size = ftell(fptr); + fseek(fptr, 0, SEEK_SET); + contents = malloc(size); + fread(contents, 1, size, fptr); + fclose(fptr); + + return contents; +} |
