ripeto:

codice:
#include "stdio.h"
#include "stdlib.h"
#include "string.h"

char *appendBefore(char *strSrcBuffer, char *strToAppend)
{
    unsigned int iSrcBufferLen = 0;
    unsigned int iStrToAppendLen = 0;
    char *strOutBuffer = NULL;

    if ( NULL == strSrcBuffer) return NULL;
    if ( NULL == strToAppend) return NULL;

    iSrcBufferLen = strlen(strSrcBuffer);
    iStrToAppendLen = strlen(strToAppend);

    strOutBuffer = (char *)malloc((iSrcBufferLen + iStrToAppendLen + 1)*sizeof(char));
    if ( NULL == strOutBuffer ) return NULL;

    strcpy(strOutBuffer, strToAppend);
    strcpy(strOutBuffer+iStrToAppendLen, strSrcBuffer);
    strOutBuffer[iSrcBufferLen+iStrToAppendLen] = '\0';

    return strOutBuffer;
}

int main(void)
{
  char *slash = "/";
  char *tmp1 = "prima";
  char *tmp2 = "seconda";
  char *tmp3 = "terza";
  char *tmp4 = "quarta";
   
  char *result = appendBefore(tmp4, slash);
  result = appendBefore(result, tmp3);
  result = appendBefore(result, slash);
  result = appendBefore(result, tmp2);
  result = appendBefore(result, slash);
  result = appendBefore(result, tmp1);

  printf(result);
}