/*
Linux API:fflush
function:实现交互式
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
void nemu(void);
void fun_sleep(const char *c);
int main(int argc, char *argv[])
{
int i = 0;
for(;;)
{
puts("\033c"); // 清屏
printf("num=%d\n", i++);
sleep(1);
nemu();
}
exit(EXIT_SUCCESS);
}
void nemu(void)
{
puts("\033c"); // 清屏
char c = ' ';
printf("1.func 1\n");
printf("2.func 2\n");
printf("3.func 2\n");
printf("please input:");
scanf("%c", &c);
getchar();
if (c == 'q')
exit(EXIT_SUCCESS);
printf("input is %c", c);
fflush(stdout);
sleep(2);
fun_sleep(&c);
}
void fun_sleep(const char *c)
{
puts("\033c"); // 清屏
printf("hello %c", *c);
//fflush(stdout);
sleep(1);
printf("over\n");
}
makefile
#!/bin/bash
target=code
CC=gcc
CFLAGS=-Wall -g
$(target):code.o
$(CC) -o $(target) code.o $(CFLAGS)
code.o:code.c
$(CC) -c code.c $(CFLAGS)
.PHONY:clean
clean:
rm -f $(target)
rm -f *.o
标签:code,void,char,sleep,交互式,printf,fflush
From: https://www.cnblogs.com/starcos/p/16846414.html