add rand number
This commit is contained in:
parent
1a336d46e3
commit
82f5a40a87
23
src/main.c
23
src/main.c
@ -1,10 +1,22 @@
|
|||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void update(WINDOW *win)
|
void get_data(int *speed, int *capacity)
|
||||||
|
{
|
||||||
|
*speed = rand() % 201;
|
||||||
|
*capacity = rand() % 101;
|
||||||
|
}
|
||||||
|
|
||||||
|
void update(WINDOW *win, int data)
|
||||||
{
|
{
|
||||||
int win_y, win_x;
|
int win_y, win_x;
|
||||||
char message[] = "test";
|
char message[64];
|
||||||
|
snprintf(message, sizeof(message), "%d", data);
|
||||||
|
|
||||||
|
werase(win);
|
||||||
|
box(win, 0, 0);
|
||||||
|
|
||||||
getmaxyx(win, win_y, win_x);
|
getmaxyx(win, win_y, win_x);
|
||||||
mvwprintw(win, win_y/2, win_x/2 - strlen(message)/2, "%s", message);
|
mvwprintw(win, win_y/2, win_x/2 - strlen(message)/2, "%s", message);
|
||||||
wrefresh(win);
|
wrefresh(win);
|
||||||
@ -16,6 +28,7 @@ int main()
|
|||||||
noecho();
|
noecho();
|
||||||
cbreak();
|
cbreak();
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
nodelay(stdscr, true);
|
||||||
|
|
||||||
int y,x;
|
int y,x;
|
||||||
getmaxyx(stdscr, y, x);
|
getmaxyx(stdscr, y, x);
|
||||||
@ -33,11 +46,13 @@ int main()
|
|||||||
wrefresh(top_win);
|
wrefresh(top_win);
|
||||||
wrefresh(bottom_win);
|
wrefresh(bottom_win);
|
||||||
|
|
||||||
|
int speed, capacity;
|
||||||
int ch = ERR;
|
int ch = ERR;
|
||||||
while(ch == ERR)
|
while(ch == ERR)
|
||||||
{
|
{
|
||||||
update(top_win);
|
get_data(&speed, &capacity);
|
||||||
update(bottom_win);
|
update(top_win, speed);
|
||||||
|
update(bottom_win, capacity);
|
||||||
ch = getch();
|
ch = getch();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user