Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Text Editor in C (Univ assignment)

Name: Anonymous 2011-01-12 4:39

So hey guys :3

I've got this paper that I have to do, and I need to make a text editor. Please assist me and offer tips as I'm currently trying to think this thing through before I get to the actual coding.

•I'm going to be saving everything in a 20x80 matrix, or a string[1601] so I can use every individual character written, is this correct? (I'm declaring the maximum number of chars on screen to 20 lines with 80 columns, fuck anything more, this is a first semester assignment, hence the matric and string lengths)

•How on earth does I shot cursor? I mean, I'm supposed to have the cursor move up and down so the user can write at different parts of his text. Now, I can think of a way to shove the characters of the string "left" or "right" by making an individual proc, but how would one actually go and make the cursor move? Any ideas would be welcome.

•I'm unfamiliar with C extracting anything in .txt format, derp, will google later. Everything we've worked so far is hurrr command prompt calculations.

•In general, any ideas from you experienced coders, feedback, tips, anything, will be bloody welcome. Although I've worked with BYOND and Space Station 13 (/tg/station13) before so I'm familiar with reading Spaghetti code or structured coding using and calling procs() (oh hey I can probably go look at the code there and gather ideas and code formations) I think I'm at a stage where, being confused, I don't even know what QUESTIONS to ask to myself before I start solving the problem.

Just for the record, im studying CS at AUTH university, greece.

Name: Anonymous 2011-01-12 4:42

Well at least you're not one of these ''''mailto:noko'''' ``faggots''.

* use ncurses
* sage when posting

Name: Anonymous 2011-01-12 4:47

>>1
while(getchar())puts("?");

I implemented for you the standard editor

For a serious response, see >>2 and we don't hurrr and derp.

Name: Anonymous 2011-01-12 4:51

>>1
I'm going to be saving everything in a 20x80 matrix, or a string[1601] so I can use every individual character written, is this correct?
It's the same.

Name: Anonymous 2011-01-12 5:02

>>3
>while(getchar())puts("?");

Printing ?s everytime you press a button. Huh.


>>2
I don't think I'm allowed to use external libraries, let me check if NCURSES comes with DevC++

>>4
So you approve of this? Do I go ahead and store everything in a silli-ly huge string?

Name: Anonymous 2011-01-12 5:05

lol

Name: Anonymous 2011-01-12 5:13

>>1
Give up programming now.

Name: Anonymous 2011-01-12 5:14

>>5
Man, we help you and you do what? Not sage. What's wrong with you?

Name: Anonymous 2011-01-12 5:16

>>8

Is the sage to keep things nice and structured around here?
Anyway. I forgot about it. Here.

Name: Anonymous 2011-01-12 5:18

... but if you don't here's my advice.

static not-growable editor = FAGGOT SHIT.

use a linked list of lines.  Each line can be a static buffer with a max of 256 or something reasonable.

That way line insertion / deletion will be fast as it's just a simple update of the list.   Insertion/deletion of characters will need an inefficient for loop pushing things forward or back one, but as lines are relevativly short it's not a problem.

how would one actually go and make the cursor move? .. wtf...IHBTC. You would require at the very least cursorx and cursory variables to store it's position on the screen.  Then some sort of viewportx variable that will store the offset of the top visible line to the top of the file.

Name: Anonymous 2011-01-12 5:29

>>10

You lost me at linked lists, since I've never worked with linked lists before. See >First semester.

Then again, I'm on /prog/.

Name: Anonymous 2011-01-12 5:34

>>11
KILL YOURSELF,  RIGHT NOW

Name: Anonymous 2011-01-12 5:49

>>12

Nope, why are you so mad?

Name: Anonymous 2011-01-12 5:53

>>11
Have you ever worked with structs, at least?

>>13
Please, don't use retarded language.

Name: Anonymous 2011-01-12 6:04

>>10
Use a skip list of lines.

Name: Anonymous 2011-01-12 6:41

>>1
just look at the source of vim lol

>>11
wrong, that variable should at least be called viewporty

Name: Anonymous 2011-01-12 7:35

>>16
U MENA "U MEAN VIEWPORTY"

Name: Anonymous 2011-01-12 7:43

>>11
I suggest you start programming in Lisp or Scheme immediately to familiarize yourself with lists.

Here's a book that might help you:
http://mitpress.mit.edu/sicp/

Name: Anonymous 2011-01-12 8:20

>>16
just look at the source of vim lol

I lolled my head in amusement.

Name: Anonymous 2011-01-12 8:56

>>1
•I'm unfamiliar with C extracting anything in .txt format
extracting
lol'd, thanks for making my afternoon OP

Still, why the [1601]?

Name: Anonymous 2011-01-12 10:03

>>20
i was also puzzled at first, but of course it's to NULL terminate

Name: Anonymous 2011-01-12 10:18

>>1

What if the user wants more than 20 symbols on a line?

[source]char **[/source]
[source]char ***[/source] if you want to implement history

Name: Anonymous 2011-01-12 10:38

>>22
[hide][source] tag doesn't exist, “““faggot”””.[/hide]

Name: Anonymous 2011-01-12 11:00

You have to decide on the platform first (such as *nix ncurses, Win32 GUI, Win32 console, plain old stdlib, multiple platforms, etc), what language you will be using (you mention C, but ``string[1601]'' sounds quite strange in that context), then on what kind of editor you want to implement (the standard editor, vi-like, emacsen-like, notepad, *Visual Enterprise IDE, whatever). Each choice you make will shape your editor considerably.

Name: Anonymous 2011-01-12 11:03


bullety gorns

   HOW DOES THEY WORK

Name: Anonymous 2011-01-12 11:16

>>21
Oh, right. But then:
NULL-terminating a fixed-length string
wat

Name: Anonymous 2011-01-12 11:22

>>26
no, the size of the viewport might change in the future.

ENTERPRISE QUALITY CODING takes future maintenance into account

Name: Anonymous 2011-01-12 11:36

>>26
I thought the same when I was making my shitty little utility programs. Then I wanted to make the smallest change. You shouldn't shun widely accepted standards to save one bit and make your number non-round, ««««‘faggot’»»»».

Name: Anonymous 2011-01-12 11:49

Does it have to be a wysiwyg editor? If not, you could just make a clone of e; it's very easy.

Name: Anonymous 2011-01-12 11:50

>>29
U MENA ed(1)?

Name: Anonymous 2011-01-12 11:52

>>30

Yes, I do, sorry about the typo.

Name: Anonymous 2011-01-12 11:56

Why would anybody write a text editor? It's a solved problem (see ms word)

Name: Anonymous 2011-01-12 11:59

>>32
I do all my codans in ms word!!! ^-^

Name: Anonymous 2011-01-12 13:13

>>27,28
Magic numbers considered unscientific and ultimately destructive. Suggestion: use #DEFINEs.

Name: Anonymous 2011-01-12 13:39

OP here.

I'm a bit lost.

We've never used pointers.
We're supposed to make it through Windows Command Prompt
We're supposed to limit the size of the editor, hence the 20x80=1600 string
Our "knowledge" goes as far as using procedures outside main(), but I've been reading on pointers alone. Frankly, I don't get em yet. I need a good 2-hour sitting reading online tutorials and I think I can get em.

Hopefully, this answers your questions.

And yes, 1601 is due to the last stringend character. Also sage.

Name: Anonymous 2011-01-12 13:43

>>34

I've actually thought about dynamically allocating more memory as the user types more stuff, instead of having a fixed string with lots of space. So I've also started reading up on malloc(), did I even spell that correctly.

I'm now trying to get the characters to actually show up on screen instead of just getting inserted to the string through getch();. Without using a for formation and a string[charcount]+printf followup.

Name: Anonymous 2011-01-12 13:52

>>35
char[20][81], it will be 20 lines of strings long 80 characters plus the NUL terminator.

You're on windows an you're studying at a pretty crappy school with pretty crappy teachers in a pretty crappy Borland implementation of C, so you should have that shitty conio.h to control the console. You can emulate curses with that.

Else, do a line editor.

For the functions to operate with files, search for fopen(3), fgets(3), fclose(3).

Name: Anonymous 2011-01-12 13:54

>>35
I don't see why pointers would be involved in this assignment.

Name: Anonymous 2011-01-12 14:11

We've never used pointers.
We're supposed to make it through Windows Command Prompt
We're supposed to limit the size of the editor, hence the 20x80=1600 string
Our "knowledge" goes as far as using procedures outside main(), but

How in the bloody disembodied fuck are they expecting you to do anything with these?

I need a good 2-hour sitting reading online tutorials
That's the equivalent of driving rusty nails through your ass when you have a headache. Just read The Book:
http://en.wikipedia.org/wiki/The_C_Programming_Language
And when you have some free time on your hands, grab a SICP.

Name: Anonymous 2011-01-12 14:14

And you probably need unbuffered input. You really should fuck the details of the assignment and use ncurses like a true UNIX neckbeard.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List