Some changes

This commit is contained in:
leca 2023-02-13 12:54:00 +03:00
parent 821670f678
commit b141712359
4 changed files with 18 additions and 15 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
test.txt test.txt
content.txt
# ---> C # ---> C
# Prerequisites # Prerequisites
*.d *.d

View File

@ -1,2 +1,2 @@
all: all:
gcc main.c -lncurses -g gcc main.c -lncurses -g -o console

BIN
console Executable file

Binary file not shown.

31
main.c
View File

@ -11,49 +11,52 @@ void clearInput() {
} }
} }
void printContent(char (*content)[cols+1]) { void printContentIntoAFile(char (*content)[cols+1]) {
FILE* f = fopen("content.txt", "w");
for (int i = rows - 2; i > 1; i --) { for (int i = 0; i < rows - 2; i ++)
mvprintw(i, 0, "%s", content[rows - 2 - i]); fprintf(f, "%s\n", content[i]);
fclose(f);
} }
void printContent(char (*content)[cols+1]) {
for (int i = rows - 2; i > 1; i --)
mvprintw(i, 0, "%s", content[rows - 2 - i]);
} }
void insertInStartContent(char (*content)[cols+1], char* toInsert) { void insertInStartContent(char (*content)[cols+1], char* toInsert) {
for (int i = rows; i > 0; i --) { for (int i = rows - 2; i > 0; i --)
strcpy(content[i], content[i - 1]); strcpy(content[i], content[i - 1]);
} strcpy(content[0], toInsert);
strcpy(content[rows], toInsert);
} }
int main (int argc, char* argv[]) { int main (int argc, char* argv[]) {
initscr(); initscr();
cbreak(); cbreak();
keypad(stdscr, TRUE); keypad(stdscr, TRUE);
noecho(); noecho();
char ch = ' '; char ch = ' ';
int len = 0; int len = 0;
char* cmd_string = malloc(128); char* cmd_string = malloc(cols);
char (*content)[cols] = malloc(sizeof(char[rows][cols+1])); char (*content)[cols] = malloc(sizeof(char[rows][cols+1]));
for (int i = 0; i < rows; i ++) { for (int i = 0; i < rows; i ++)
strcpy(content[i], " "); memset(content[i],0,sizeof(content[i]));
}
getmaxyx(stdscr, rows, cols); getmaxyx(stdscr, rows, cols);
while (ch = getch()){ while (ch = getch()){
switch (ch) { switch (ch) {
case 10: { case 10: {
// char* toInsert = malloc(cols+1);
FILE* f = fopen("test.txt","w"); FILE* f = fopen("test.txt","w");
fprintf(f, "test: %s", cmd_string); fprintf(f, "test: %s", cmd_string);
fclose(f); fclose(f);
insertInStartContent(content, cmd_string); insertInStartContent(content, cmd_string);
len = 0; len = 0;
clearInput(rows, cols); clearInput(rows, cols);
cmd_string = malloc(128); memset(cmd_string,0,cols * sizeof(char));
refresh(); refresh();
printContentIntoAFile(content);
break; break;
} }
default: default: