View Single Post
Old 2004-06-19, 10:27 AM   #7
sperry
The Doink
 
sperry's Avatar
 
Real Name: Scott
Join Date: Nov 2002
Location: Portland, OR
Posts: 20,335
 
Car: '09 OBXT, '02 WRX, '96 Miata
Class: PDX/TT-6
 
The way out is through
Default

Code:
#include <stdio.h>

enum ExeInstructions = { exeSUBMIT_POST, exeSUBMIT_REPLY };

class PostReply
{
  private:

  char* text_buf;
  char* quote_buf;

  public:

  PostReply(void)
  {
    text_buf = NULL;
    quote_buf = NULL;
  }

  ~PostReply(void)
  {
    if (text_buf) delete[] text_buf;
    if (quote_buf) delete[] quote_buf;
  }

  void setQuote(char* author, char* text)
  {
		int buf_len = strlen(author) + strlen(text) + 20;
		
		if (quote_buf) delete[] quote_buf;
		quote_buf = new char[buf_len];
		
		strncpy(quote_buf, "[quote=\"", buf_len);
		strncat(quote_buf, author, buf_len);
		strncat(quote_buf, "\"]\n", buf_len);
		strncat(quote_buf, text, buf_len);
		strncat(quote_buf, "[/quote]", buf_len);
  }

	void setMessageText(char* text)
	{
		int buf_len = strlen(text) + 1;
		
		if (text_buf) delete[] text_buf;
		text_buf = new char[buf_len];
		
		strncpy(text_buf, text, buf_len);
	}
	
	void execute(ExeInstructions exe)
	{
		switch (exe)
		{
			case exeSUBMIT_POST:
				printf("New Post:\n%s", text_buf);
				break;

			case exeSUBMIT_REPLY:
				printf("Reply:\n%s\n\n%s", quote_buf, text_buf);
				break;
		}
	}

};

int main(void)
{
  PostReply* pr = new PostReply("nKoan");
  pr->setQuote("nKoan", "And don't even get me started on how I think computer science has fucked up my thought processes.");
  pr->setMessageText("tell me about it!");
  pr->execute(exeSUBMIT_REPLY);
  delete pr;
  return 1;
}
Quote:
Originally Posted by nKoan
And don't even get me started on how I think computer science has fucked up my thought processes.
tell me about it!
__________________
Is you is, or is you ain't, my con-stit-u-ints?
sperry is offline   Reply With Quote