Added segmentation fault :)
This commit is contained in:
parent
66b6b36754
commit
a1c8231640
23
main.c
23
main.c
|
@ -14,7 +14,7 @@ void clearInput() {
|
||||||
void printContent(char (*content)[cols+1]) {
|
void printContent(char (*content)[cols+1]) {
|
||||||
|
|
||||||
for (int i = rows - 2; i > 1; i --) {
|
for (int i = rows - 2; i > 1; i --) {
|
||||||
mvprintw(rows - i, 0, "%s", content[rows - 2 - i]);
|
mvprintw(i, 0, "%s", content[rows - 2 - i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,19 +22,19 @@ void insertInStartContent(char (*content)[cols+1], char* toInsert) {
|
||||||
for (int i = rows; i > 0; i --) {
|
for (int i = rows; 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(cols);
|
||||||
char (*content)[cols+1] = 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], " ");
|
strcpy(content[i], " ");
|
||||||
|
@ -44,16 +44,21 @@ int main (int argc, char* argv[]) {
|
||||||
|
|
||||||
while (ch = getch()){
|
while (ch = getch()){
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 10:
|
case 10: {
|
||||||
char* toInsert = malloc(cols+1);
|
// char* toInsert = malloc(cols+1);
|
||||||
mvscanw(rows - 1, 0, "%s", toInsert);
|
FILE* f = fopen("test.txt","w");
|
||||||
insertInStartContent(content, toInsert);
|
fprintf(f, "test: %s", cmd_string);
|
||||||
|
fclose(f);
|
||||||
|
insertInStartContent(content, cmd_string);
|
||||||
len = 0;
|
len = 0;
|
||||||
clearInput(rows, cols);
|
clearInput(rows, cols);
|
||||||
|
cmd_string = "";
|
||||||
refresh();
|
refresh();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
mvprintw(rows - 1 , len, "%c", ch);
|
mvprintw(rows - 1 , len, "%c", ch);
|
||||||
|
cmd_string[len] = ch;
|
||||||
len ++;
|
len ++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
4
test.c
4
test.c
|
@ -13,10 +13,10 @@ void insert (char (*content)[cols], char* toInsert) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main () {
|
int main () {
|
||||||
cols = 20;
|
cols = 50;
|
||||||
rows = 3;
|
rows = 3;
|
||||||
|
|
||||||
char (*content)[cols] = malloc(sizeof(char[rows][cols+1]) * 10);
|
char (*content)[cols] = malloc(sizeof(char[rows][cols+1]));
|
||||||
|
|
||||||
strcpy(content[0], "Test string 1");
|
strcpy(content[0], "Test string 1");
|
||||||
strcpy(content[1], "Test string 2");
|
strcpy(content[1], "Test string 2");
|
||||||
|
|
Loading…
Reference in New Issue