Last active
August 21, 2017 07:49
-
-
Save HorlogeSkynet/e99159ed5ba1737a632c55d356f41889 to your computer and use it in GitHub Desktop.
A simple C function to clear the terminal without using the bad `system("clear")`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <errno.h> | |
#include <sys/wait.h> | |
void sky_clear(void) | |
{ | |
pid_t status = fork(); | |
switch(status) | |
{ | |
case -1: | |
printf("Couldn\'t \'fork()\' the current process into a child: %s\n", strerror(errno)); | |
break; | |
case 0: | |
if(execvp("clear", (char *const[]){"clear", NULL}) == -1) | |
{ | |
printf("Couldn\'t \'exec()\' the command: %s\n", strerror(errno)); | |
exit(EXIT_FAILURE); | |
} | |
exit(EXIT_SUCCESS); | |
default: | |
wait(&status); | |
break; | |
} | |
} | |
int main(int argc, const char *argv[]) | |
{ | |
(void)argc; | |
(void)argv; | |
sky_clear(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment