如何实现“加载屏幕”?

时间:2021-03-30 12:35:13

标签: c function main time.h

有没有办法调用loading_screen()然后在三秒后清屏然后再进入程序??

#include <stdio.h>
    
    void loading_screen() {
        printf("\n*\t *\t *\t *\t *\t *\t *\t *\n* Welcome to your blah blah! *\n*\t *\t *\t *\t *\t *\t *\t *\n\n");
    }
    
    void starting_screen() {
        printf("1. add new recipe\n");
        printf("2. search for recipe\n");
        printf("3. delete recipe\n");
    }
    
    int main(int argc, char *argv[]) {
        loading_screen();
        starting_screen();
        return 0;
    }

1 个答案:

答案 0 :(得分:2)

您可以在 windows 上使用 system("cls"); 或在 linux 上使用 system("clear"); :

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
    
    void loading_screen() {
        printf("\n*\t *\t *\t *\t *\t *\t *\t *\n* Welcome to your blah blah! *\n*\t *\t *\t *\t *\t *\t *\t *\n\n");
    }
    
    void starting_screen() {
        printf("1. add new recipe\n");
        printf("2. search for recipe\n");
        printf("3. delete recipe\n");
    }
    
    int main(int argc, char *argv[]) {
        loading_screen();
        sleep(3);
        system("cls");//system("clear");
        starting_screen();
        return 0;
    }