le code on c'est jamais
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include "windows.h"
#include <iostream>
#include "ressource.h"
using namespace std;
int FileExists(char* cfname)
{
return (GetFileAttributes(cfname) != 0xFFFFFFFF);
}
void help(){cout<<"liste de commande :\n\n open\t\t\touvre un fichier selectionn\202\n"
<<"\n more\t\t\taffiche la selection de la command ouvrir\n\n help\t\t\t"
<<"affiche l'aide\n\n quit\t\t\tfait quite le programme\n\n"
<<" ccs\t\t\teffac\202 l'\202cran\n\n change\t\t\tmodifie le fichier "
<<"selectionn\202 par la command open\n\n";}
command O;
main()
{
char cSaisie[50];
char cCom[10];
int i=0;
ccs:
cout<<"\t\t\t\tAFDOS\t0.0.1\n";
main:
int iSwitch=0;
cout<<">>";
cin>>cCom;
if (!strcmp(cCom,"quit")){return 0;}else
if (!strcmp(cCom,"open")){iSwitch=1;}else
if (!strcmp(cCom,"more")){iSwitch=2;}else
if (!strcmp(cCom,"ccs")){iSwitch=5;}else
if (!strcmp(cCom,"change")){iSwitch=6;}else
if (!strcmp(cCom,"help")) {iSwitch=3;}else{iSwitch=4;}
switch(iSwitch)
{
case 1:
cout<<"\n\ntapez le nom/chemin d'axai du fichier a ouvrir\n>";
cin>>cSaisie;
if(FileExists(cSaisie)==true){i=1;O.open(cSaisie);}
else{cout<<"\nchemin d'axai erron\202\n";}
break;
case 2:
if(i!=0){ O.affiche();}
else{cout<<"vous n'avez pas ouvert de fichier\n";}
break;
case 3:
help();
break;
case 4:
cout<<cCom<<" n'est pas une command\ntapez help pour la liste de command\n\n";
goto main;
break;
case 5:
system("CLS");
goto ccs;
break;
case 6:
if(i!=0){O.modif(cSaisie);}
else{cout<<"vous n'avez pas ouvert de fichier\n";}
break;
}//fin de switch
cout<<endl;
goto main;}
#ifndef _ressource_h
#define _ressource_h
using namespace std;
class command
{
public :
void open( char*cName)
{
fStr.open(cName, fstream::in | fstream::binary); //Ouvrir le fichier en lecteur
fStr.seekg(0, ios::end); //Trouver la fin du fichier
iNumChrs = fStr.tellg(); //Lire le nombre d'octets
fStr.seekg(0, ios::beg); //Revenir au début
cBuf = new char [iNumChrs]; //Redimensionner l'espace tampon avant
fStr.read(cBuf, iNumChrs); //d'accueilir les données
fStr.close(); //Sans oublier de fermer le filestream
cout<<"fichier "<<cName<<" ouvert\n";
}
void affiche(){cout<<cBuf<<endl;}
int modif(char*cName)
{
char cCf[MAX_PATH];
cout<<">";
cin>>cCf;
ofstream Fichier(cName);
Fichier <<cCf;
Fichier.close();
cout<<"\nfichier "<<cName<<" a \202t\202 modifi\202\n";
cBuf=cCf;
}
private:
int iNumChrs;
fstream fStr;
char *cBuf;
};
#endif