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

Pages: 1-4041-8081-

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.

Name: Anonymous 2011-01-12 15:03

this thread sucks.

Name: Anonymous 2011-01-12 15:45


@echo off
echo This is MY editor, i made it....
pause
edit %1 %2

Name: Anonymous 2011-01-12 16:35

>>42
time ttwo bust out THE EDITing porgram....
lets EDIT this......
where making this happen......

Name: Anonymous 2011-01-13 1:29

>>39

Aye, got it. Got the C Bible through univ book distribution, I believe it's the same.

also, the lack of that knowledge is only temporary, as it's most probably second semester teaching material.
Due to a lot of students being here through Philosophical schools (as we have them in greece) they haven't worked with programming before, so we have to re-take the entire thing from the start, from a basic indented if to how to include libraries.

Name: Anonymous 2011-01-13 1:34

>>44
If the publisher was deranged enough to rename the K&R to anything involving the word ``Bible'', I'd ditch it and get the real thing. They're dirt-cheap now, you could rob a homeless man and buy the book with his one day's earnings.

Name: Anonymous 2011-01-13 4:55

I concur gentlemen here. Do a line editor.  We don't need yet another clone of edit.exe.
We need more clones of ed. Don't forget about regexes.

Name: Anonymous 2011-01-13 5:04

>>46
We need more clones of ed.

ed(1) is already perfect.

Name: Anonymous 2011-01-13 9:30

ed has too many commands, it needs to be streamlined

Name: Anonymous 2011-01-13 9:33

#include <stdlib.h>

int main(void)
{
    return system(getenv("EDITOR"));
}

Name: Anonymous 2011-01-13 11:31

>>47
Ed is a little sucky, actually. If it didn't take four extra characters to type sam -d I wouldn't use ed at all.

Name: Anonymous 2011-01-13 11:45

>>50
Go back to cat-v.org

Name: Anonymous 2011-01-13 11:52

>>47
Keep telling yourself that. DeNile it's not just a large body of water on the north coast of Africa.

Name: Anonymous 2011-01-13 12:12

Name: Anonymous 2011-01-13 13:12

This message was typed on a CHERRY G80-3000

Name: Anonymous 2011-01-13 13:18

This message was typed on Emacs using Conkeror's edit-current-field-in-external-editor, bind to C-i

Name: Anonymous 2011-01-13 14:48

[hide]kill yourself[/hide]

Name: Anonymous 2011-01-13 14:48

<hide>kill yourself</hide>

Name: Anonymous 2011-01-13 14:54

\hide{kill yourself}

Name: Anonymous 2011-01-13 15:04

>>58
Back to your basement, old man. Get to writing volume six!

Name: Anonymous 2011-01-13 17:06

>>58
Did you seriously just try using LATEX to do [o][u][i][b]BBCode's job?

Name: Anonymous 2011-01-13 17:06

>>60
FUCK

Name: Anonymous 2011-01-13 17:11

>>60,61
Learn to BBCode

Name: Anonymous 2011-01-13 18:49

>>60
It was a viable SexpCode alternative at one point.

Name: Anonymous 2011-01-14 6:30

2^6 GET

Name: Back to /b/, !uaVa00FkCs 2011-01-14 6:33

>>64
Back to /b/, ``please''.

Name: Anonymous 2011-01-14 6:40

>>65
Fuck off, ``faggot''.

Name: Back to /b/, !uaVa00FkCs 2011-01-14 6:42

>>66
Back to /b/, ``please''.

Name: Fuck off, !Ep8pui8Vw2 2011-01-14 6:44

>>67
Fuck off, ``faggot''.

Name: Back to /b/, !uaVa00FkCs 2011-01-14 6:46

>>68
Back to /b/, ``please''.

Name: Fuck off, !Ep8pui8Vw2 2011-01-14 6:47

>>69
Fuck off, ``faggot''.

Name: Back to /b/, !uaVa00FkCs 2011-01-14 6:47

>>70
Back to /b/, ``please''.

Name: Fuck off, !Ep8pui8Vw2 2011-01-14 6:48

>>71
Fuck off, ``faggot''.

inb4 back to /b/

Name: Back to /b/, !uaVa00FkCs 2011-01-14 6:49

>>72
Back to /b/, ``please''.

anon delivers

Name: Anonymous 2011-01-14 6:53

>>65-73
ONE WORD: HAX MY ANUS

Name: Anonymous 2011-01-14 8:16

I agree with >>73.

Name: Anonymous 2011-01-14 12:30

>>73
fuck off faggot

Name: Anonymous 2011-01-14 12:49

sage for >>76's faggotry

Name: Anonymous 2011-01-14 13:34

>>77
bump for >>77's faggotry

Name: Anonymous 2011-01-14 13:38

>>78
noko for >>78's faggotry

Name: Anonymous 2011-01-14 13:50

>>79
Noko doesn't work on a text board,``faggot''.
Away with ye; and heigh thyself back to /b/, sodomite.

Name: Anonymous 2011-01-14 14:00

with mail = #fortune
A fatal error occured!
That password is wrong!
>>80 #fortune for >>80's faggotry

Name: Fuck off, !Ep8pui8Vw2 2011-01-14 15:24

>>80
Fuck off, you cock sucking homosexual.

Name: Back to /b/, !uaVa00FkCs 2011-01-14 15:25

>>82
Back to /b/, autistic dick loving African American.

Name: Anonymous 2011-01-14 21:03

>>83
don't you understand? you can't win. now go cry yourself to sleep, kiddie.

Name: Anonymous 2011-01-14 22:10

>>84
Don't you understand plain English? Back to /b/, please.

Name: Anonymous 2011-01-14 22:55

>>85
fuck off, faggot

Name: Anonymous 2011-11-17 22:56

neat

Name: Anonymous 2011-11-17 22:58

juden

Name: Anonymous 2011-11-18 4:38

Almost all modern text editors use the Rope data structure to represent text, which allows for efficient operations on very long strings.

http://en.wikipedia.org/wiki/Rope_%28computer_science%29

Name: Anonymous 2011-11-18 5:00

>>89
Why not finger trees?

Name: Anonymous 2011-11-18 5:40

>>89
rope is such a shit name for that

Name: Anonymous 2011-11-18 8:12

SYSTEM("edit")

Name: Anonymous 2011-11-18 9:45

>>89
Emacs uses cons because it has no choice.

Name: Anonymous 2011-11-18 11:15

>>93
Emacs
Linux is a great operating system, all it lacks is a good kernel.

Name: Anonymous 2011-11-18 12:47

>>93
Back to Google groups, Xah.

Name: Anonymous 2011-11-18 12:57

>>95
I don't know who that is, but Lisp is shit, and cons bullshit doesn't help.

Name: Anonymous 2011-11-18 13:54

>>96
Lisp is shit
no u

Name: Anonymous 2011-11-18 14:33

>>97
Lisp is shit.

Name: Anonymous 2011-11-23 10:03

<span style="background: #3a15eb; color: #e3fd43; ">candy-ass</span>

Name: Anonymous 2011-11-23 10:31

>>100
get

Name: Anonymous 2011-11-24 11:31

>>111
sweet triples bro

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