Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 320232
- OSLab 2 2_1.c
- Vlad Ungureanu [email protected]
- */
- #include <ncurses.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- #include <unistd.h>
- static char *rand_string (char *str, size_t size) {
- const char charset[] = "abcdefghijklmnoprstuvwxyzABDCEFGHIJKLMNOPRSTUVWXYZ";
- if (size) {
- --size;
- size_t n;
- for (n = 0; n < size; n++) {
- int key = rand() % (int) (sizeof charset -1);
- str[n] = charset[key];
- }
- str[size] = '\0';
- }
- return str;
- }
- static char *empty_string (char *str, size_t size) {
- size_t n;
- for (n = 0; n < size; n++)
- str[n] = ' ';
- str[size] = '\0';
- return str;
- }
- char* rand_string_alloc (size_t size) {
- char *s = malloc (size + 1);
- if (s) {
- srand (time(NULL));
- int tmp = rand() % 10;
- if (tmp < 7)
- rand_string(s, size);
- else empty_string(s, size);
- }
- return s;
- }
- void makeStrigs(char*** strings, int col) {
- (*strings) = (char**)malloc(sizeof(char*) * col);
- int x = 0;
- int y = 0;
- if((*strings) == NULL) {
- printf("Not good!");
- exit(1);
- }
- for(x = 0; x < col; x++) {
- (*strings)[x] = (char*)malloc(sizeof(char) * 1000);
- if((*strings)[x] == NULL) {
- printf("Not good!");
- exit(1);
- }
- for(y = 0; y < 1000; y++) {
- if(x % 3 != 0)
- (*strings)[x][y] = rand() % 90 + 32;
- else
- (*strings)[x][y] = ' ';
- }
- }
- }
- void dealloc(char** strings, int col) {
- int i;
- for(i = 0; i < col; i++)
- free(strings[i]);
- free(strings);
- }
- void print_matrix(char** strings, int col) {
- int x, y, ct = 0;
- while(ct != col) {
- for(x = 0; x < col; x++)
- for(y = 0; y < ct; y++)
- mvprintw(y, x, "%c", strings[x][ct-y]);
- ct++;
- refresh();
- usleep(50000);
- }
- }
- int main(int argc, char **argv) {
- int row, col;
- char** strings;
- srand(time(NULL));
- initscr(); /* start the curses mode */
- start_color(); /* needed to use colors */
- init_pair(5, COLOR_GREEN, COLOR_BLACK); /* set foreground and background pair indexed as 5 */
- getmaxyx(stdscr, row, col); /* get the number of rows and columns */
- attron(COLOR_PAIR(5)); /* set color style to 5: magenta-black pair (see below) */
- makeStrigs(&strings, col);
- print_matrix(strings, col);
- endwin();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment