#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    10
    Rep Power
    0

    C Text Editor Problems


    Guys, if i want to create a text editor using C
    with the following requirements:
    Using 2d array to handle multiple lines of text.
    Delete and Replace Characters and Words.


    How can i go abt doing it?
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    Take a stab at it and ask us about specific problems you are having.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    10
    Rep Power
    0
    The below coding only search and replaces a character at a time, how can i edit in such a way that it also search and replaces a string at a time.

    int replaceChar(char *sN){
    int count=0;
    char sC,rC;
    printf("\nEnter a search character:");
    scanf("%c",&sC);
    fflush(stdin);
    printf("\nEnter a replacement character:");
    scanf("%c",&rC);
    while(*sN != '\0'){
    if(*sN==sC){
    *sN=rC;
    count++;
    }
    ++sN;
    }
  6. #4
  7. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    Please use "code" tags (http://forums.devshed.com/misc.php?action=bbcode&s=).

    You will have to create a second buffer to copy the changed string. Making single character changes is easy because the length of the result is exactly the same as the input. There is a small chance that will happen with random replacement strings, but you can't trust that will happen. You will want to create your buffer for the replacement at least as long as the maximum possible length. This is far from impossible, but does intail alot of bookkeeping which is why so many libraries exist for that sort of thing. Also, don't forget to deallocate your buffer once you are done with it, else you will have a resource leak that could take a long time to track down.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    10
    Rep Power
    0
    but lets say i just want to change a word like "zoo" to "farm"
    how can i code it?
  10. #6
  11. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    Give it a try, that is how best to learn.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  12. #7
  13. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,112
    Rep Power
    1803
    #include <string.h>

    Get a reference to the C string library and learn and understand it. Your compiler's library may have extensions to the ANSI library to handle case insensitivity for example.

    The GNU string.h documentation is here. The functions that are not standard are indicated as such. Your compiler may well have the same ones, or equivilants with different names.

    Clifford.

IMN logo majestic logo threadwatch logo seochat tools logo