aboutsummaryrefslogtreecommitdiff
path: root/std/stdio.c
blob: b5f1dd04472bb3f2fb56dba5fc5fee2c28d3af54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <stdlib.h>

char* readln() {
    char* str = malloc(128);
    scanf("%127s", str);
    return str;
}

void print(char *str) {
   fputs(str, stdout);
}

void termpos(int x, int y) {
    printf("\x1b[%d;%dH", x, y);
}

void termclear() {
    printf("\x1b[2J\x1b[H");
}

void curshide() {
    print("\x1b[?25l");
}

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;
}