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.
>>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.
Is the sage to keep things nice and structured around here?
Anyway. I forgot about it. Here.
Name:
Anonymous2011-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.
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.
>>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:
Anonymous2011-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.
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.
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.
>>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:
Anonymous2011-01-12 13:54
>>35
I don't see why pointers would be involved in this assignment.
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.
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.
>>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.