Thread: Simple text editor help

  1. #16
    Registered User
    Join Date
    Jul 2007
    Posts
    131
    One tip: Don't use array for holding the contents. It won't work.
    Another tip: Gap or list.

  2. #17
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by fronty View Post
    One tip: Don't use array for holding the contents. It won't work.
    Another tip: Gap or list.
    Of course an array can be used to hold text content...

    Code:
    char TextBuf[1000][81];
    One thousand lines 80 characters wide.

  3. #18
    Registered User
    Join Date
    Jul 2007
    Posts
    131
    That won't be very practical. If you delete the first character in a line, you have to shift other 79 characters back one place, and when the user enters a new character in the beginning of the line, you have to shift them back. IF you don't use some kind of delay in the changes to the actual buffer, or use another buffer containing a copy of current line or something somewhere else. Still that doesn't work well when user enters completely new line. You have to shoft all the lines further in the buffer.

    I still say gap buffer or list. First one is traditionally used in emacsen and the latter is used very well in fancy eds also known as vis and are easy to implement.

  4. #19
    Registered User
    Join Date
    Dec 2010
    Posts
    8
    So I'm doing some tests here, but I'm stuck. How will the computer know if one of the arrow keys is pressed?
    I'm thinking something like that:
    if(string=="user presses right arrow")
    {
    x++;
    gotoxy(x,y);
    }
    but what will the code for "user presses right arrow be? I'm thinking of putting the ASCII code for the arrow keys but I can't find anything.
    Just for testing I'm using a string and not an array or something else.

  5. #20
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    That depends on how you're getting input. If you're doing a keyboard poll, you'd have to check whether right-arrow is in a key-down state. If you're getting signals, then you're "strange" keys have special values that depend on what library you're using.

  6. #21
    Registered User
    Join Date
    Dec 2010
    Posts
    8
    Hmmm....I never heard my professor tell us anything about this stuff, it can't be that difficult. Right now I'm using stdlib,stdio and screentUtils libraries.

  7. #22
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You're not going to get arrow keys (or control-whatever key combinations) using stdio. stdio only gives you line-buffered input -- your program doesn't see anything until the user presses Enter, and then all it sees is the final result in one rush.

    If you want to be able to type arrow keys and actually have it work, then you'll need to get closer to the hardware.

  8. #23
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by fronty View Post
    I still say gap buffer or list. First one is traditionally used in emacsen and the latter is used very well in fancy eds also known as vis and are easy to implement.
    This is a beginner exercise. This guy has less than 2 weeks to write an editor.

    Simple wins over better this time.

  9. #24
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Fink View Post
    Hmmm....I never heard my professor tell us anything about this stuff, it can't be that difficult. Right now I'm using stdlib,stdio and screentUtils libraries.
    That's interesting... Do you have a copy of the exact assignment he gave you?

    Text editors are not what I would call a "beginner exercise"....

  10. #25
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Arrays can work OK, but I wouldn't use 10,000 lines for this. Three or four times the number of chars you show on a single page of your editor, should be fine.

    @fronty: yes, you shift char's - no, it's not professional - yes, it will do for a beginner's exercise.

  11. #26
    Registered User
    Join Date
    Jul 2007
    Posts
    131
    Quote Originally Posted by CommonTater View Post
    This is a beginner exercise. This guy has less than 2 weeks to write an editor.

    Simple wins over better this time.
    I think using linked list containing every line on a node inside some very simple malloc'd dynamic array implementation won't be very hard, even simpler with hard coded maximum line length like in your implementation. This will make creating and destroying lines work better and won't be hard to implement. Similar situation with gap buffer, it isn't really far from simple array implementation, but makes operations work better. It won't be hard for a beginner if he know basic data structures.

  12. #27
    Registered User
    Join Date
    Jan 2011
    Posts
    7
    Hi guys! I m obviously a co-student of fink and i have the same assignment... We could use a character arrow but not any dynamic solution since we haven't taught anything about pointers(we only use them -but without really knowing- in loading and saving text(fopen,etc).

  13. #28
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    463
    Quote Originally Posted by pSyXaS View Post
    Hi guys! I m obviously a co-student of fink and i have the same assignment... We could use a character arrow but not any dynamic solution since we haven't taught anything about pointers(we only use them -but without really knowing- in loading and saving text(fopen,etc).
    Is there a question coming? Or is this it?
    "All that we see or seem
    Is but a dream within a dream." - Poe

  14. #29
    Registered User
    Join Date
    Jan 2011
    Posts
    7
    Mainly it's an explanation about the assignment data, but i also haven't done anything... I generally imagine it as a character arrow in which there will be some "if"(for example if the user hits backspace-8 in ascii table- go to the previous place). My most important problem is how to make the status bar...

  15. #30
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Do you mind if I ask how far you are into this course?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  2. Simple Text Parsing.. Long Time Since College
    By chops11 in forum C Programming
    Replies: 4
    Last Post: 10-07-2004, 04:00 PM
  3. Replies: 5
    Last Post: 02-01-2003, 10:58 AM
  4. text simple question
    By Unregistered in forum Game Programming
    Replies: 2
    Last Post: 04-26-2002, 09:45 AM
  5. simple text dialog ok cancel
    By Brian in forum Windows Programming
    Replies: 1
    Last Post: 02-12-2002, 02:20 AM