Developing Text editors in C

C

Cheeks

Hi all,

Has anyone here developed a text editor using C ? If so pls share
the ideas with me.

I have some basic doubts on how to edit the text in stdout as per the
input from keyboard.

Also whenever the user inputs any characted to a IO function like
scanf, the character is displayed in stdout.. how can I block it.

Regards,
Cheekuu
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Hi all,

Has anyone here developed a text editor using C ? If so pls share
the ideas with me.

I have some basic doubts on how to edit the text in stdout as per the
input from keyboard.

Also whenever the user inputs any characted to a IO function like
scanf, the character is displayed in stdout.. how can I block it.

You can't make a good texteditor unless you use some kind of thurd-party
library for controlling the console (unless you want to make a new ed).
Since you are talking about standard in/out I suspect you are targeting
Unix/Linux (under windows you'd probably be looking into using a GUI) in
which case you might be interested in ncurses.
 
N

Neo

Hi all,

Has anyone here developed a text editor using C ? If so pls share
the ideas with me.

I have some basic doubts on how to edit the text in stdout as per the
input from keyboard.

Also whenever the user inputs any characted to a IO function like
scanf, the character is displayed in stdout.. how can I block it.

Regards,
Cheekuu

Erik is right in pointing out that without using some third-party
library, you would end up dealing with just too much of esoterism.
Though, NCurses is good enough to develop any basic editing tool,
empirical experiences have taught me that it takes just too much of
code to get even the most basic thing upright running, in the context
of providing the window where text would be typed, maintaining those
buffers in sync and odd!

Since this is a C++ group, I inevitably suggest the below.

Take a look into the Trolltech's C++ framework called QT, it is
available for free and comes along with the neccessary editor, make
tool and help pages. The framework defines a class "QTextEditor" which
builds into it, most of the editing capabilities you are looking for.

--Neo
 
J

James Kanze

Has anyone here developed a text editor using C ? If so pls share
the ideas with me.

You should probably ask in a C newsgroup (comp.lang.c), and not
here. The appropriate solutions in C++ won't be legal C, by a
long shot.
I have some basic doubts on how to edit the text in stdout as per the
input from keyboard.

An editor won't normally edit text in stdout (nor in cout in
C++). It will edit text in a buffer. That buffer is normally
filled by reading a file, and saved afterwards by writing to a
file.
Also whenever the user inputs any characted to a IO function like
scanf, the character is displayed in stdout.. how can I block it.

You mean: how do you turn off echoing? (The character is *not*
displayed in stdout. It is echoed at a much lower level.) The
simple answer is that you can't. For a more complex answer, see
below.

This sounds a bit like a school project, since anyone really
writing an editor today would already be thinking in terms of
windows in a GUI (and the company would also put a least one
person with real experience on the project, to whom you'd be
asking questions before posting here). If you really know that
little about it, I'd very strongly suggest you get the book
"Software Tools in Pascal", by Kernighan and Plauger. (Dispite
the title, the code is "Pascal" only with regards to the actual
syntax; it's very, very C-like in style---not surprising
considering the authors:). Also note that the book is very
dated, and I'm sure that at least Plauger would not hesitate to
use classes and other C++ features were he writing it in C++,
today. But the ideas are still valid, and very well presented.)
Amongst the tools they describe is a simple command line editor,
which is probably about all you'll be able to accomplish in a
school project (and which is also a good start for a more
complex editor).

If you want or need to go beyond a simple command line editor,
the next step would be to use a portable library to manage
"windows" in a terminal: curses/ncurses seems to be the de facto
standard. And the same thing more or less applies for a GUI:
I'd check out wxWidgets, if I were you. (This commits you to
real C++, and not just C. But you don't really want to write
anything as complicated as a GUI in C anyway.) But be aware
that the issues are complex, and try to only take on one thing
at at time.
 
G

Guillermo Schwarz

I've done it.

First implement editing a line in NCurses. You must cover all border
cases: arrows, delete, backspace, tab, etc.
Then allow to move from one line to the next using the arrows.
Then use a model (the whole text of the document) and show a part in a
window (the previous prototype you just created) and you will be done
in a month or two.

If you want to go the quick way, take a look at Notepad++.
 
T

Thomas Dickey

Guillermo Schwarz said:
I've done it.
First implement editing a line in NCurses. You must cover all border
cases: arrows, delete, backspace, tab, etc.
Then allow to move from one line to the next using the arrows.
Then use a model (the whole text of the document) and show a part in a
window (the previous prototype you just created) and you will be done
in a month or two.

It depends on what you need. I wrote an editbox widget for dialog in
a few days (about 600 lines). That uses an pre-existing input module
which handles multibyte characters (700 lines). The border cases you
mention are the trivial part of the implementation...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top