OS1/directories/input.c

35 lines
499 B
C
Raw Permalink Normal View History

#include "input.h"
int integer_input(char* val) {
int num;
char *error = "";
do {
printf("%s\n%s",error, val);
fflush(stdout);
char buf[128];
read(STDIN_FILENO, buf, 127);
num = atoi(buf);
error = "\nInput Error, try again.";
} while(!num);
return num;
}
2023-10-30 03:25:48 -07:00
char* string_input(char* val) {
char* string = malloc(sizeof(char) * 1000);
printf("%s", val);
fflush(stdout);
ssize_t n = read(STDIN_FILENO, string, 1000);
string[n - 1] = '\0';
return string;
}