Reputation: 27
I am programming a simple text editor in C and I defined a structure named node and created a linked list named textbuffer. I am trying to create an insert function for the text editor. Here is the code so far:
#include <stdio.h>
#include <string.h>
struct node
{
char statement[40];
int next;
};
struct node textbuffer[25];
void insert(int line, char* stat)
{
FILE *file;
file=fopen("texteditor.txt","a");
if(file!=NULL)
{
int i;
int k;
strcpy(textbuffer[line].statement,stat);
textbuffer[line].next=line+1;
fprintf(file,textbuffer[line].statement);
}
else
{
printf("File couldn't found.");
}
fclose(file);
}
Now I need to take the current cursor position in the file, and for example, when the input is "w", I need to get the cursor up or when the input is "z" , I need to get the cursor down and write there some text. If I explain with a photo:
I tried to do that with wherex() and wherey() methods but conio.h library didn't work in linux. Do I have to do it with methods in conio.h" library? If so, how? Or is there any other way?
Upvotes: 0
Views: 611
Reputation: 12292
You can do all kinds of cursor manipulation and many more screen manipulation (insert, delete, clear, select color and more) using escape sequences. This can be done under Linux using the ncurses library which does it almost whatever the terminal is. But today, most if not all terminals are supporting XTerm escape sequences which inherit from ANSI, VT100 and VT52. This also works in Windows 10. Have a look at this Wikipedia article for more information.
You may also look at this detailed documentation.
Upvotes: 1