All pastes #1668302 Raw Edit

wayne

public c v1 · immutable
#1668302 ·published 2009-11-12 15:26 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <string.h>#include "stringbuffer.h"stringBuffer* newStringBuffer(){ stringBuffer *new; new = malloc(sizeof(stringBuffer)); if (new == NULL) printf("Stringbuffer konnte nicht erstellt werden.\n"); new->top = NULL; return new;}void stringBufferAppend(stringBuffer* buffer, char* text){  stringBufferElement *new, *tmp;  new = malloc(sizeof(stringBufferElement));  if (new == NULL) printf("StringBufferElement konnte nicht erstellt werden.\n");  tmp = buffer->top;  buffer->top = new;  new->next = tmp;  new->value = malloc(strlen(text)+1);  strcpy(new->value, text);}void stringBufferInsert(stringBuffer* buffer, int address, char* text){  stringBufferElement *new, *tmp;  int i;  new = malloc(sizeof(stringBufferElement));  if (new == NULL) printf("StringBufferElement konnte nicht erstellt werden.\n");  tmp = buffer->top;  if (address == 1) {    buffer->top = new;    new->next = tmp;  } else {      for (i = 2; i < address; i++) {tmp = tmp->next;}      new->next = tmp->next;      tmp->next = new;    }  new->value = malloc(strlen(text)+1);  strcpy(new->value, text);}void stringBufferConcatenate(stringBuffer* buf1, stringBuffer* buf2){  stringBufferElement *tmp;  tmp = buf2->top;  while (tmp != NULL) {    stringBufferAppend(buf1, tmp->value);    tmp = tmp->next;  }  free(buf2);}void stringBufferSort(stringBuffer* buf){}int stringBufferLength(stringBuffer* buf){  stringBufferElement *tmp;  int count = 0;  tmp = buf->top;  while (tmp != NULL) {    count++;    tmp = tmp->next;  }  return count;}void stringBufferPrint(stringBuffer* buf){  stringBufferElement *tmp;  tmp = buf->top;  while (tmp != NULL) {    printf("%s\n", tmp->value);    tmp = tmp->next;  }}