The program below is written in C and creates a structure that holds the values of a text editor. This structure is beneficial during the development of text editor applications. Let me know if you find the code below helpful and if you have any additional suggestions:

/*-----------------------------------------------------------
 * Description: Program that creates a text editor struct
 *-----------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXSIZE 100

typedef enum {false, true} bool;
typedef struct textnode textnode_t;

struct textnode {
    char thechars[MAXSIZE+1]; //storage for characters
    bool newpara;        //true if this starts a new paragraph,false otherwise
    textnode_t *next;   // pointer to sturct textnode
    int char_size;      // size of the chars
    int newpar_pos;     // new paragraph position
};

struct text{
    textnode_t *first;  // points to the first node in the list 
    unsigned length;     // holds total length of text
};

Can you provide an example of how someone can use this code in an editor? For example, a text editor class that actually utilizes this struct? Otherwise, on its own, there's not much value here. Why does the textnode need to include a pointer to the next textnode? What are you expecting gets stored in the new paragraph position? What is the purpose of a boolean for whether the node starts a paragraph or not?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.