Added getMaskChar function. Also swapped out some explicit null pointers with NULL

modified:   src/nms.c
This commit is contained in:
Brian Barto 2016-04-08 15:34:07 -04:00
parent a175b434ed
commit dd89bbc721
1 changed files with 21 additions and 6 deletions

View File

@ -1,9 +1,11 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <ctype.h> #include <ctype.h>
#include <stdbool.h> #include <stdbool.h>
#include <time.h>
#define SPACE 32 #define SPACE 32
#define NEWLINE 10 #define NEWLINE 10
@ -11,10 +13,12 @@
int getTermSizeRows(void); int getTermSizeRows(void);
int getTermSizeCols(void); int getTermSizeCols(void);
void clearTermWindow(int, int); void clearTermWindow(int, int);
char getMaskChar(void);
int main(void) { int main(void) {
struct winpos { struct winpos {
char source; char source;
char mask;
int row; int row;
int col; int col;
struct winpos *next; struct winpos *next;
@ -25,6 +29,9 @@ int main(void) {
int termSizeRows = getTermSizeRows(); int termSizeRows = getTermSizeRows();
int termSizeCols = getTermSizeCols(); int termSizeCols = getTermSizeCols();
// Seed my random number generator with the current time
srand(time(NULL));
// Geting input // Geting input
int c, x = 1, y = 1; int c, x = 1, y = 1;
bool first = true; bool first = true;
@ -45,9 +52,10 @@ int main(void) {
} }
list_pointer->source = c; list_pointer->source = c;
list_pointer->mask = getMaskChar();
list_pointer->row = y; list_pointer->row = y;
list_pointer->col = x; list_pointer->col = x;
list_pointer->next = (struct winpos *) 0; list_pointer->next = NULL;
++x; ++x;
} }
@ -57,16 +65,15 @@ int main(void) {
// Printing the list // Printing the list
list_pointer = start; list_pointer = start;
while (list_pointer != (struct winpos *) 0) { while (list_pointer != NULL) {
printf("row: %i, ", list_pointer->row); printf("\033[%i;%iH%c", list_pointer->row, list_pointer->col, list_pointer->mask);
printf("col: %i, ", list_pointer->col);
printf("char: %c\n", list_pointer->source);
list_pointer = list_pointer->next; list_pointer = list_pointer->next;
} }
printf("\n");
// Freeing the list. // Freeing the list.
list_pointer = start; list_pointer = start;
while (list_pointer != (struct winpos *) 0) { while (list_pointer != NULL) {
temp = list_pointer; temp = list_pointer;
list_pointer = list_pointer->next; list_pointer = list_pointer->next;
free(temp); free(temp);
@ -103,3 +110,11 @@ void clearTermWindow(int pRows, int pCols) {
// Position cursor at the top // Position cursor at the top
printf("\033[%i;%iH", 1, 1); printf("\033[%i;%iH", 1, 1);
} }
char getMaskChar(void) {
char *maskChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"1234567890";
return maskChars[rand() % strlen(maskChars)];
}