How do you make C edit text? As in run the cursor over it and change it?
How do you make C edit text? As in run the cursor over it and change it?
That is a very short question with a very long answer. To write a VERY simple editor is about 300 lines of code, I expect. [In fact, I did one as a "challenge" not so long ago - it was 274 lines in the main file, and a linked-list handling file of another 108 lines - along with one header-file of a few lines of prototypes copied from the linked-list source].
Of course, that is to load a text-file, edit it in some simple ways (delete line, add line), and save it back out again.
To "mark" text by for example holding shift and using the arrow-keys will involve some form of system-dependant code (or a system-independent library that does the system-dependant parts FOR YOU).
Of course, if we are not talking console, but a full Windows or Xwindows application, then it is both simpler and harder, as some things are done for you, but you need to write more code in other places simply to achieve a window on the screen, etc.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
You need a setting for the text on screen (which is where the cursor is). This is probably WAY more complicated than you might have hoped. After all, barking up this tree won't really cut it:
Have a look into ncurses() or an actual GUI library.Code:#include <stdio.h> int main() { printf("XX XX\b\b\b\bY"); }
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
I don't want a GUI, and I don't care how long it takes, please just tell me how.
http://www.adrianxw.dk/SoftwareSite/index.html
http://pdcurses.sourceforge.net/
Read both, and learn about controlling the console screen.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Do you have any links for controlling the console screen?
You can't. I believe what you want to do and what matsp was talking about are not quite the same thing -- his program did not allow you to back the cursor up the screen and actually delete and replace something on the screen. Or I will eat an egg.
ncurses() runs in the console (ie, from the command-line); a lot of old pre-net era applications were that way. It's easier to use than a GUI API, but it will still take you awhile. There are some tutorials around. ncurses() is actually quite neat.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
So it is either a GUI or ncurses?
No eggs needed here.
I have written code to walk about on the screen for various purposes (including implementig an Emacs-like editor written in PDP-11 assembler on 68K). But just handling the keyboard/screen in Windows or Linux is a major undertaking - I'd expect that to be at least 2-300 lines of code just to be able to put some text up and move about within it. That doesn't include any actual EDITING - that will add even more code. I counted up some 380 lines of code to do the other basic bits, and that's with a fair bit missing for editing a line of text in the way you can in DOS's "EDIT".
Yes, it can be done - and you can either use some curses version (pd or n) or you can write your own functions to move within the text on screen yourself. But if you have never done it before, you will probably end up spendig QUITE A LOT of time just doing that.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
You haven't given me any idea how to write my own functions to do that.
What function(s) do you want me to give you ideas for? If you are using windows, you need to interface to the Console Functions. There are some of that in the FAQ, the rest is on the MSDN site http://msdn.microsoft.com/en-us/libr...73(VS.85).aspx
I'm sorry, but this forum isn't the "post a few lines of question and get 2-300 lines of working code" - you must have got us confused.
If you are using Linux/Unix, you need to use ANSI escape sequences (if you need this, try googling for "wiki ansi escape sequence" and try the "I'm feeling lucky" button).
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Thanks for the Microsoft link.
Would it be easier in x86 assembly?
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge