1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #include <stdlib.h>
#include <assert.h>
/*
sczSource : Nom de fichier source (essai1.txt)
sczRepDestination : Nom de répertoire destination (saisi par l'utilisateur)
sczFichDestination : Nom de fichier destination (essai2.txt)
*/
void copieFichierEx(char const * const sczSource, char const * const sczRepDestination, char const * const sczFichDestination)
{
size_t const nLenRepDest = strlen(sczRepDestination);
size_t const nLenFichDest = strlen(sczFichDestination);
size_t const nLenDest = nLenRepDest + 1 + nLenFichDest;
/* Je mets le sizeof, c'est plus facile pour passer en wchar_t */
char * const szDest = calloc(nLenDest+1, sizeof(*szDest));
/* Ici, on peut utiliser strcpy()+strcat(), ou être un peu casse-cou. */
strcpy(szDest, sczRepDestination);
strcat(szDest, "\\");
strcat(szDest, sczFichDestination);
/* Normalement, le dernier caractère est déjà nul.
Mais on peut vérifier: */
assert(szDest[nLenRepDest+1+nLenFichDest] == '\0');
/* On appelle la fonction de copie */
copieFichier(sczSource, szDest);
/* On libère la mémoire allouée */
free(szDest);
} |