need help, badly

This is a discussion on need help, badly within the C Programming forums, part of the General Programming Boards category; ok, to anyone who cares, I have been trying to create a workable function that will edit the text within ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    1

    Exclamation need help, badly

    ok, to anyone who cares, I have been trying to create a workable function that will edit the text within a string to a decent extent, i.e. basic functions, printable cahracters, enter, left and right arrows, backspacing, and also being able to show the cursor in the correct space.

    so far i have had very little success, if anyone has a method of doing this i would be most grateful for same advice as to how to go about it. new lines are the killer when trying to get the cursor in the right spot, that and inserting. I have even tried using a two dimensional character array, rows and columns, but that has its problems too.

    I just want some advice so that i can have some idea which method i should try to use. thanks in advance

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You've also apparently had little success in reading the forum guidelines. Here:

    Quote Originally Posted by kermi3
    Welcome to the boards. If you haven't already done so then please take some time to familiarise yourself with the faq:
    http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

    Make sure you have a look at the the posting guidelines:
    http://cboard.cprogramming.com/annou...ouncementid=51
    Following the rules will ensure you get a prompt answer to your question.

    Remember, too, that the board has a search facility, a link is at the top of your screen:
    http://cboard.cprogramming.com/search.php
    It will often get you a quicker answer to your questions than waiting for a response to one you have posted.

    It appears that you are posting a homework assignment or other project.

    Please don't ask people to do all your work for you, See the announcement on Homework at the top of all forums to see what is acceptable or PM me. Basically people are happy to help, but they're not going to do it all for you.

    Show us what you've got, show your code (using code tags), or where you're confused and someone will be happy to help you I'm sure. If it's something that you absolutely don't understand how it works, like you have no clue how qsort works, then ask a general question about the function and I'm sure someone will explain it. Though they may not give you all of the code for it, but someone will explain the concept.


    On obivous homework questions especially, I like to remind people of the board's ninth guildeline, while this board is very helpful to people, make sure you have your instructor's permission before seeking help on assignments. While people on these boards are more than happy to help, we discourage people from asking for help on graded work without the instructor's permission, and we claim no repsonsibilty for any cheating or honor violations.

    Feel free to PM me with any questions.

    Good Luck,

    Kermi3

    Read and follow the above instructions, and try your post (in the same thread) again.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Well you need to separate the storage of the data from the display on screen.

    Code:
    while ( 1 ) {
      do_action( editor );
      refresh_display( editor );
    }
    editor being a data structure containing
    - all the text
    - the current cursor position

    do_action() is simply concerned with keeping the database up to date, based on your user actions.
    refresh_display() is simply concerned with generating a visual representation of that which is easy for the user to understand.

    My idea would be
    Code:
    typedef struct {
      lines *beforelines; /* a linked list of lines preceding the cursor */
      lines *afterlines;  /* a linked list of lines following the cursor */
      char *prechars;     /* chars on the current line, before the cursor */
      char *postchars;    /* chars on the current line, after the cursor */
      int  cx;
      int  cy;            /* current cursor pos */
    } editor;
    You'll probably want a 'line' data structure rather than a simple char* to manage memory allocation better.

    The most common action - typing in new characters is simply
    prechars[cx++] = ch;

    As you move the cursor around, then left/right move chars between prechars and postchars
    Up/down cursor movements change the linked lists accordingly as well, again, nothing particularly expensive since all you do is move a few pointers, and perhaps one line of data.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. is my loop badly set up?
    By mabufo in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2006, 02:40 PM
  2. char arrays, pointers, etc, could use help badly
    By Nakeerb in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2002, 10:20 PM
  3. Newbie needs C++ help with pauses- help needed badly.
    By dgprog in forum C++ Programming
    Replies: 2
    Last Post: 07-11-2002, 05:11 PM
  4. peeves that pet... really badly about the language... of C/++... that is...
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 12-16-2001, 03:12 PM
  5. need some advice...badly.
    By heavyd in forum C++ Programming
    Replies: 1
    Last Post: 12-12-2001, 03:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21