943,164 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 526
  • C RSS
Mar 13th, 2010
0

text editor with commands

Expand Post »
I have to now make a simple single line text editor where the letters i type i can use commands to edit them this is what I started with my knowledge and so far ive got typing happening, if its possible to just input commands that can change the lines I type.

  1.  
  2. #include <stdio.h>
  3.  
  4. #define MAX 100
  5. #define LEN 80
  6.  
  7. char text[MAX][LEN];
  8.  
  9. int main(void)
  10. {
  11. register int t, i, j;
  12.  
  13. printf("Enter an empty line to quit.\n");
  14.  
  15. for(t = 0; t < MAX; t++) {
  16. printf("%d: ", t);
  17. gets(text[t]);
  18. if(!*text[t])
  19. break; /* quit on blank line */
  20. }
  21.  
  22. for(i = 0; i < t; i++) {
  23. for(j = 0; text[ i ][ j ]; j++)
  24. putchar(text[ i ][ j ]);
  25. putchar('\n');
  26. }
  27.  
  28. return 0;
  29. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Idontknowc is offline Offline
10 posts
since Mar 2010
Mar 13th, 2010
0
Re: text editor with commands
you might want to get a copy of edlin line editor and see how it worked.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2281
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,938 posts
since Aug 2005
Mar 13th, 2010
0
Re: text editor with commands
Wow! Edlin takes me back. Used it in my first computer language, BASIC.

Now I find it hiding in WindowsXP, and still working!!
Reputation Points: 416
Solved Threads: 181
Nearly a Posting Virtuoso
Adak is offline Offline
1,463 posts
since Jun 2008
Mar 13th, 2010
2
Re: text editor with commands
>this is what I started with my knowledge and so far ive got
What you started with your knowledge? Nah, you just copied it from C: The Complete Reference by Herbert Schildt.
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Mar 14th, 2010
0
Re: text editor with commands
Quick question... How are you supposed to edit the test ?
Reputation Points: 114
Solved Threads: 104
Master Poster
abhimanipal is offline Offline
736 posts
since Dec 2009
Mar 14th, 2010
0
Re: text editor with commands
Quick question... How are you supposed to edit the test ?
That was one of the OP's questions in his original post.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2281
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,938 posts
since Aug 2005
Mar 14th, 2010
0
Re: text editor with commands
If what he wants is a LINE editor, then he should follow the functionality you can see in Edlin. That was a terrific suggestion from Ancient Dragon.

As far as editing, I'd definitely want to use a compiler with conio.h or ncurses, which have that getch() feature. Also, the gotoxy(), is there as well (although Windows gives you SetConsoleCursorPosition(), which does the same, but it's a bit clumsier). Couple that with wherex(), and wherey(), and you're off to a good start, imo.

The multi-line editor is the better editor, no doubt. The Edlin type (one line at a time) editor is the much easier one to program, however.

So he needs to decide what he wants.
Last edited by Adak; Mar 14th, 2010 at 7:44 pm.
Reputation Points: 416
Solved Threads: 181
Nearly a Posting Virtuoso
Adak is offline Offline
1,463 posts
since Jun 2008
Mar 15th, 2010
0
Re: text editor with commands
edlin was a really nice text editor for its time. I did all my C program using it for MS-DOS.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2281
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,938 posts
since Aug 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: printing a structure in a function by calling it from another structure
Next Thread in C Forum Timeline: Help with bubble sorting





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC