Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <assert.h>
- #include <string.h>
- #include "texbuffer.h"
- typedef struct textbuffer *TB;
- typedef struct node *link;
- struct textbuffer{
- link start;
- link end;
- int numberoflines;
- };
- struct lineImp{
- char *text[];
- link next;
- link prev;
- };
- /* Allocate a new textbuffer whose contents is initialised with the text given
- * in the array.
- */
- link newNode(char text[]){
- struct lineImp * newLine = malloc(sizeof(text[]));
- newLine->next = NULL;
- newLine->prev = NULL;
- return newLine;
- }
- TB newTB (char text[]){
- link newLine;
- int i = 0;//array counter
- TB *newBuffer = malloc(sizeof(struct textbuffer));
- assert(newBuffer !=NULL);
- newBuffer->start = newLine;
- newBuffer->end = newLine;
- char *token;
- char *previousToken;
- /* get the first token */
- previosToken = strtok(text[], '\n');
- int lineLength = 0;
- /* walk through other tokens */
- while( token != NULL )
- {
- struct lineImp * newLine = malloc(sizeof((token-previousToken)+1));
- if(newBuffer->start != NULL){
- newBuffer->start = newLine
- newLine->next = NULL;
- newline->prev = newBuffer->start;
- } else{
- struct link curr;
- }
- previousToken = token;
- token = strtok(NULL, s);
- }
- /* while(text[i] != '\0'){
- temp = text[i];
- if(text[i] == '\n'){
- newNode(text[i]-temp + 1);
- }
- i++;
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement