Simple text editor help

This is a discussion on Simple text editor help within the C Programming forums, part of the General Programming Boards category; Do you mean what we have taught so far?...

  1. #31
    Registered User
    Join Date
    Jan 2011
    Posts
    7
    Do you mean what we have taught so far?

  2. #32
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Yeah... Like I'm thinking if you're in second year or something this may be a reasonable project but it's one flat out dirty trick to dump it on someone in the first month.

  3. #33
    Registered User
    Join Date
    Jan 2011
    Posts
    7
    It's a first semester course in which we have learnt the basics of C and more specificaly data types,I/O,loop and if(and switch-case) statements,Functions,arrays and structures... I m at the 3rd semester but i haven't passed the course so i reattend it...

  4. #34
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    455
    You are being really vague about the assignment. I think you have no clue what the assignment actually requires. Since your class is only intro stuff, your assignment wouldn't be as complicated as the OP's would be since his would have to do the output dynamically on the screen. I'm just going to guess here that your text editor would just consist of typing something into the buffer then print it out.
    Go read the tutorial from this forum. And you may want to start a new thread with the exact assignment AND the code that you have attempted. What you are doing is basically this: I am clueless about what's going on, I wish someone has some code that fit the descriptions.
    "All that we see or seem
    Is but a dream within a dream." - Poe

  5. #35
    Registered User
    Join Date
    Jan 2011
    Posts
    7
    I don't know about my co-student that started the thread but my problem is very specific i think and doesn't require-in my opinion again- the code that i have or don't have... I never asked for a code i just asked for a thought about how i could create a status bar at the last line of a program...
    Last edited by pSyXaS; 01-14-2011 at 01:08 PM.

  6. #36
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    How about asking for some help from the guy whose salary you pay to teach you?

  7. #37
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Specify what the parameters of the status bar, are. That is, status of what?. Status bars I'm familiar with are just a simple graphical representation (but may be done in terminal mode too), of a simple mathematical calculation of some kind.
    Last edited by Adak; 01-14-2011 at 01:57 PM.

  8. #38
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Adak View Post
    Specify what the parameters of the status bar, are. That is, status of what?. Status bars I'm familiar with are just a simple graphical representation (but may be done in terminal mode too), of a simple mathematical calculation of some kind.
    I'm guessing he means something like the mode line in Emacs, or the bottom line in nano.

  9. #39
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Since I've never seen either one, I'll back out of here.

  10. #40
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    Since I've never seen either one, I'll back out of here.
    Basically it's a reverse video bar at the bottom of the screen... line #, column #, filename, stauts messages, etc. When the screen scrolls the bar stays put...

  11. #41
    Registered User
    Join Date
    Jan 2011
    Posts
    3
    Hello! I am co-student with the guy who started this thread. I'd like to help me.

    First of all, I have almost completed this text editor project (type special charactes like arrow keys and move the cursor to a user-specific position, type normal characters and print them in an 80 x 20 console's display area (80 columns x 20 rows), push enter and move the cursor down one line, backspace key's function etc..). I have a problem with the backspace function. Let the cursor be in the first column (0) and in a row bigger than first row (let it be row 1). Let the position of the last character in the previous row 0 be 45 x 00. When I push the backspace key, the cursor moves one position backwards and deletes the preceding character with printf(" "). Unfortunately, the 35 preceding characters are NULL characters and so I have to push the backspace key 35 times to delete the last character of row 0. Any ideas to improve the code? I'm using a two-dimensional array keystrokes[col][row] to store the ASCII values of the keystrokes and the function gotoxy(column,row) to move the cursor.

    BACKSPACE if else statements:
    Code:
               if (column>0)
                         {
                                 gotoxy(column-1,row);
                                 printf(" ");
                                 keystrokes[row][column-1]=' ';
                                 gotoxy(column-1,row);
                                 --column;
                         }
                         else if (column==0 && row>0)
                         {
                              column=79;
                              gotoxy(column,row-1);
                              printf(" ");
                              keystrokes[row-1][column]=' ';
                              gotoxy(column,row-1);
                              --row;
                         }
    Last edited by Sartre; 01-15-2011 at 10:33 AM.

  12. #42
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So don't automatically go to column 79, but rather to the last actual character of row n-1.

  13. #43
    Registered User
    Join Date
    Jan 2011
    Posts
    3
    Quote Originally Posted by tabstop View Post
    So don't automatically go to column 79, but rather to the last actual character of row n-1.
    Ok, done! Now I want to search for a word into my 2D array. If the word exists, the cursor must be moved in the beginning of the word. How can I do this function? Probably with gotoxy(col,row) and strstr() functions. But how? The strstr() function returns a pointer to the first occurrence of str2 in str1, or NULL if no match is found. How can I move the cursor in the beginning of the word.

    Also, if the characters of a word are stored into cells [78][0], [79][0], [0][1], [1][1], [2][1] , how can I search for the word and find it?

  14. #44
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If result_from_strstr is a pointer to the middle of the array, and row_n is a pointer to the beginning of the array, then result_from_strstr - row_n tells you the index of that pointer in the array.

    If the characters of a word are stored in cells [78][0], [79][0], [0][1], [1][1], and [2][1], then you don't want to find the word in that case. I certainly wouldn't want any editor I use to report "word found" if it happened to find it going down a column. And for that matter, even if you had the characters at [0][78], [0][79], [1][0], [1][1], and [1][2], that's two different words, since you wouldn't split a word over a line break.

  15. #45
    Registered User
    Join Date
    Jan 2011
    Posts
    3
    Quote Originally Posted by tabstop View Post
    If result_from_strstr is a pointer to the middle of the array, and row_n is a pointer to the beginning of the array, then result_from_strstr - row_n tells you the index of that pointer in the array.
    First of all, thanks for the idea! I have a serious problem. This is the code I've written:

    Code:
    int i, row;
    void *index;
    char *row_n, *result, word[15], keystrokes[20][81];
    
    printf("Word to find: ");
    fgets(word, sizeof(word), stdin);
    
         for (i=0;i<20;i++)    /* 20 lines */
         {
             row_n=keystrokes[i];
             if ((result=strstr(keystrokes[i],word))!=NULL)     /* keystrokes[i]=&keystrokes[i][0] */
             {    
                 index=result-row_n;
                 row=i;
                 gotoxy(index,row);
             }
             else
            {
                 printf("There's No Such Word");
            }
         }
    My program crashes when I run this code. Is the code properly written? How can I find the index of that pointer in the array and what about the gotoxy(col,row) function?
    Last edited by Sartre; 01-17-2011 at 05:03 PM.

Page 3 of 4 FirstFirst 1234 LastLast
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, 02: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, 09: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, 01:20 AM

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