How to write data into SD card?

Hello! im new in Arduino.
im using Arduino duemilanove and MicroSD module and i want to make a program that can read and write data to the SD card…

the program to read the data from SD card already successful but i do not know how to modify the coding so that it also can write data…
here is the coding to read data;

#include <WProgram.h>
#include "mmc.h"
#include "microfat.h"

#define NOT_ENABLED 0
#define READ 1
#define WRITE 2

#define EOL '.'  // used to end the package to write to the board
#define EOF 0  // used to mark end of file

byte buffer[512];
int inByte = -1;
int mode = NOT_ENABLED;

int powerSD = 8;

static unsigned long sector, length;

void setup(void)
{
  Serial.begin(115200);
  pinMode(powerSD, OUTPUT);
  digitalWrite(powerSD, HIGH);
}


void loop(void)
{
  if (Serial.available() > 0) {
    inByte = Serial.read();
    switch (inByte) {
    case 'R':
      mode = READ;
      break;
    case 'W':
      mode = WRITE;
      break;
    default:
      mode = NOT_ENABLED;
      break;
    }
  }

  if (mode == READ)
  {
    mmc::initialize();

    if (microfat::initialize(buffer))
    {

      Serial.println("locate");

      if (microfat::locateFileStart("hola.txt", sector, length))
      {
        Serial.println("read");
        if (RES_OK == mmc::readSectors(buffer, sector, 1))
        {
          if (length > BYTESPERSECTOR)
            length = BYTESPERSECTOR;

          for(int i = 0; i < length; ++i)
          {
            Serial.print(buffer[i], BYTE);
          }

        }
      }
    }
    Serial.println();
    Serial.println("Done Reading");
    mode = NOT_ENABLED;
  }

Library + example (storing 2 bytes in a temporary buffer and then writing them to the card):
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206874649/8

… and here is a temperature to SD-Card logger (see the last post):
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1257531430/15