copier un fichier sous linux
bonjour à tous,
voici mon code en c, supposé copier un fichier.
Code:
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 33 34 35 36 37 38
| #include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
int copier_fichier(char const * const source, char const * const destination)
{
FILE* fSrc;
FILE* fDest;
char buffer[512];
int NbLus;
if ((fSrc = fopen(source, "rb")) == NULL)
{
return 1;
}
if ((fDest = fopen(destination, "wb")) == NULL)
{
fclose(fSrc);
return 2;
}
while ((NbLus = fread(buffer, 1, 512, fSrc)) != 0)
fwrite(buffer, 1, NbLus, fDest);
fclose(fDest);
fclose(fSrc);
return 0;
}
int main()
{
copier_fichier("bidule", "copy/bidule");
return EXIT_SUCCESS;
} |
lorsque je le lance sous linux, ce script me renvoie :
Code:
bash: ./main: Permission non accordée
le dossier copy existe déja, est il créé si ce n'est pas le cas?
et pourquoi linux (même en root) ne veut il pas copier mon fichier?
merci à vous ;)