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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| #include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "sys/types.h"
#include "dirent.h"
int _tmain(int argc, _TCHAR* argv[])
{
#define MAX_NAME 40
char nomfichier[MAX_NAME];
struct dirent *lecture;
DIR *rep;
rep=opendir("???" ); que mettre ici ? un chemin relatif ? par rapport a quel fichier du projet ? Chemin absolu ?
int n;
FILE *source;
FILE *destination;
int nbligne=1,nbcoma=0;
int c;
while((lecture = readdir(rep)))
{
strcpy(nomfichier,lecture->d_name);
n=strlen(nomfichier);
if(((nomfichier[n-1])='d') || ((nomfichier[n-2])='p') || ((nomfichier[n-3])='s') || ((nomfichier[n-4])='.'))
{
source = fopen(nomfichier,"r" );
if(source == NULL)
{
printf("le fichier n'existe pas\n" );
return 0;
}
else printf("le fichier existe et est ouvert\n" );
nomfichier[n-1]='t';
nomfichier[n-2]='x';
nomfichier[n-3]='t';
destination = fopen(nomfichier,"w" );
if(destination == NULL)
{
printf("le fichier n'existe pas\n" );
return 0;
}
else printf("le fichier existe et est ouvert\n" );
}
//traitement
fclose(source);
fclose(destination);
}
return 0;
} |
Partager