Crash a l'execution mais non en mode de debuggage

cybermatthieu Messages postés 7 Date d'inscription vendredi 9 mai 2003 Statut Membre Dernière intervention 30 septembre 2004 - 18 juil. 2003 à 17:40
cybermatthieu Messages postés 7 Date d'inscription vendredi 9 mai 2003 Statut Membre Dernière intervention 30 septembre 2004 - 21 juil. 2003 à 16:21
La si je roule le programme avec le mode de debugage tout fonctionne a merveille il termine l'execution normalement. Mais si je roule le programme ( sans etre dans le mode de debugage) il plente. Esque j'aurais un fuite de memoire qui arrive a l'occasion mais qu'en debugage ca ne derange pas? Peut-etre devrege demanger une reserve de memoire avant l'execution etant donner que ma class conprend que des pointeurs et que je cree par la suite un tableau ( 1124 ) de ma class?

Merci,
Matt
voici ma class:
class Permit{
char *no;
char *num;
char *holder;
char *detenteur;
char *modeOfTransport;
char *modeDeTransport;
char *issueDate;
char *emissionDate;
char *expiryDate;
char *expirationDate;
char *realFileName;
char *goodFileName;

Permit();
Permit( char no[], char num[], char holder[], char detenteur[],
char modeOfTransport[], char modeDeTransport[], char issueDate[],
char emissionDate[], char expiryDate[], char expirationDate[]);
Permit( char no[], char num[], char holder[], char detenteur[],
char modeOfTransport[], char modeDeTransport[], char issueDate[],
char emissionDate[], char expiryDate[], char expirationDate[],
char realFileName[], char goodFileName[]);
Permit(char fName[], char fPath[]);
Permit(Permit &permit);
~Permit();
Permit& operator=( const Permit &permit);
int cpyData( char text[], const char newText[]);
int catData( char text[], const char newText[]);

public:
void afficher();
char * getGoodName( char no[], char expDate[]);
int setFilePermit(char fName[], char fPath[]);
void zero(const char text[]="\0");

friend ostream& operator<<( ostream &out, const Permit &p);
friend ofstream& operator<<( ofstream &out, const Permit &p);
friend void main();
};
Les pointeur sert a l'allocation dynamique... j'utilise New puis Delete...

2 réponses

fredcl Messages postés 547 Date d'inscription mercredi 8 janvier 2003 Statut Membre Dernière intervention 7 octobre 2007 1
19 juil. 2003 à 18:58
Il faudrait l'implémentation des fonctions menbres de ta classe pour y voir un peu plus clair!

A+
Fred
0
cybermatthieu Messages postés 7 Date d'inscription vendredi 9 mai 2003 Statut Membre Dernière intervention 30 septembre 2004
21 juil. 2003 à 16:21
voila mon implantation:
//-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/
// Auteur : Matthieu Levesque
// Date : 2003/06/24
// Desc : Ce programme sert a construire un index des permits
//-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/

#include
#include <fstream>

using namespace std;

#include "Permit_Index.h"

int nbSpc( const char text[]){
int nbSpc=0;
for( int x=0 ; x<strlen(text) ; x++){
if(text[x]==' '){
nbSpc++;
}
}
return nbSpc;
}
int isComma( const char text[]){
int isComma=0;
for( int x=0 ; x<strlen(text) ; x++){
if(text[x]==','){
isComma = x;
x = strlen(text);
}
}
return isComma;
}
bool isBr( const char text[]){
bool isBr=0;
int nbChar=strlen(text);
for(int x=0 ; x<nbChar ; x++){
if(strnicmp(&text[x],"
",4)==0){
isBr=1;
}
}
return isBr;
}

void clFrstCh( char text[]){
char *temp;
bool isDone=0;
temp=new char[ strlen(text) + 1];
for(int x=0 ; x<strlen(text) ; x++){
if( (text[x]>=65 && text[x]<=91) || (text[x]>=97 && text[x]<=123) ){
strcpy(temp,&text[x]);
x=strlen(text);
isDone=1;
}
}
if(isDone){
strcpy(text,temp);
}
delete []temp;
}

void remBigSpc( char text[]){
char *temp;
int nbChTemp=0;
bool oneSpcPlz=0;
temp = new char[ strlen(text) + 2 ];
for( int t=0 ; t<strlen(text) ; t++){
if(t<strlen(temp)-1){
temp[t] = 'E';
}
}
temp[t] = '\0';
for(int x=0 ; x<strlen(text) ; x++){
while( text[x]==' '){
x++;
oneSpcPlz=1;
}
if(oneSpcPlz){
oneSpcPlz=0;
temp[nbChTemp]=' ';
nbChTemp++;
}
temp[nbChTemp]=text[x];
nbChTemp++;
}
temp[nbChTemp]='\0';
if(temp[strlen(temp)-1]==' '){
temp[strlen(temp)-1]='\0';
}
strcpy(text,temp);
delete []temp;
}

bool clString( char text[]){
bool isBr=0, isBal=0, willBal=0;
int numSearch=0, nbChTemp=0, nbChPP=0;
char *temp, chSearch[]="<>";
temp = new char[strlen(text)+1];
for( int t=0 ; t<strlen(text) ; t++){
if(t<strlen(temp)-1){
temp[t] = 'E';
}
}
temp[t] = '\0';
for( int x=0 ; x<strlen(text) ; x++){
if(willBal){
isBal=0;
willBal=0;
}
if( strnicmp(&text[x]," ",6)==0){
x+=6;
}
if( strnicmp(&text[x],"
",4 )==0){
isBr=1;
}
if( text[x]==chSearch[numSearch] ){
if(numSearch==1){
willBal=1;
numSearch=0;
}
else{
isBal=1;
nbChPP=x;
numSearch++;
}
}
if(!isBal){
temp[nbChTemp]=text[x];
if(temp[nbChTemp]=='’'){
temp[nbChTemp]='\'';
}
nbChTemp++;
}
}
if(isBal && !willBal){
strcpy(&temp[nbChTemp],&text[nbChPP]);
nbChTemp += strlen(&text[nbChPP]);
}
temp[nbChTemp]='\0';
strcpy(text,temp);
remBigSpc( text );
delete []temp;
return isBr;
}

int clDate( char date[]){
char *temp, *revDate, *mois, *jour, *anne;
int charNo, x, lastCh, nowCh;
if( strlen(date)>0 ){
temp = new char[strlen(date) + 1];
strcpy(temp,date);
if(nbSpc(date)<2){
revDate = new char[strlen(date) + 2];
strcpy(revDate,date);
for( x=0 ; x<strlen(date) ; x++){
nowCh=static_cast(date[x]);
if( x>0 && ((lastCh>=65 && lastCh<=90) ||
(lastCh>=97 && lastCh<=122)) && (nowCh>=48 && nowCh<=57)){
strcpy(&revDate[x+1],&temp[x]);
revDate[x]=' ';
}
lastCh=nowCh;
}
delete []temp;
temp = new char[strlen(revDate)+1];
strcpy(temp,revDate);
delete revDate;
}
strtok(temp,"/");
mois = strtok(temp," ");
jour = strtok(&temp[strlen(mois)+1]," ");
anne = &temp[strlen(mois)+strlen(jour)+2];
x=0;
while(strlen(anne)>4 && x<=5){
if(anne[0]==','){
strcpy(anne,&anne[1]);
}
if(anne[0]==' '){
strcpy(anne,&anne[1]);
}
if(anne[4]==' '){
anne[4]='\0';
}
x++;
}
strcpy(date,anne);
strcat(date,"/");
if(stricmp(mois,"january")==0 || strnicmp(mois,"jan",3)==0){
strcat(date,"01/");
}
else if( strnicmp(mois,"feb",3)==0){
strcat(date,"02/");
}
else if( strnicmp(mois,"mar",3)==0){
strcat(date,"03/");
}
else if( strnicmp(mois,"apr",3)==0){
strcat(date,"04/");
}
else if( strnicmp(mois,"may",3)==0){
strcat(date,"05/");
}
else if( strnicmp(mois,"jun",3)==0){
strcat(date,"06/");
}
else if( strnicmp(mois,"jul",3)==0){
strcat(date,"07/");
}
else if( strnicmp(mois,"aug",3)==0){
strcat(date,"08/");
}
else if( strnicmp(mois,"sep",3)==0){
strcat(date,"09/");
}
else if( strnicmp(mois,"oct",3)==0){
strcat(date,"10/");
}
else if( strnicmp(mois,"nov",3)==0){
strcat(date,"11/");
}
else if( strnicmp(mois,"dec",3)==0){
strcat(date,"12/");
}
else{
strcat(date,"Er/");
}
charNo = isComma(jour);
if(charNo>0){
jour[charNo]='\0';
}
if(strlen(jour)<2){
strcat(date,"0");
}
strcat(date,jour);
delete []temp;
}
return 0;
}
//Fonction qui met en memoire la liste de fichier
int listFileMem( char list[][MAX]){
//Creation d'un fichier temporaire contenants la liste de fichiers
system("dir *.htm /s /b /o:n > Temp.txt");
//Inicialisation du compteur nbLigne
int nbLigne = 0;
//Creation de l'objet fstream fIn
fstream fIn;
//Ouverture du fichier temporaire
fIn.open("Temp.txt", ios::in );
//Condition si une erreur se produit
if( !fIn ) {
//Fermeture du programme
exit( 1 );
}
//Lecture du fichier ligne par ligne
while(!fIn.eof()){
//Lecture et mise en memoire de la ligne du fichier
fIn.getline(list[nbLigne],MAX);
//Forcage de fin de chaine de caractere au point
strtok(list[nbLigne],".");
//Augmente le compteur nbLigne
nbLigne++;
}
//Fermeture du fichier
fIn.close();
//Commande system qui supprime le fichier temporaire
//system("del temp.txt");
//Retourne le nombre de fichiers
return nbLigne-1;
}
Permit::Permit( char no[], char num[], char holder[], char detenteur[],
char modeOfTransport[], char modeDeTransport[], char issueDate[],
char emissionDate[], char expiryDate[], char expirationDate[]){
//Allocation dynamique de la memoire
this->no = new char[strlen(no)+1];
/*this->num = new char[strlen(num)+1];
this->holder = new char[strlen(holder)+1];
this->detenteur = new char[strlen(detenteur)+1];
this->modeOfTransport = new char[strlen(modeOfTransport)+1];
this->modeDeTransport = new char[strlen(modeDeTransport)+1];
this->issueDate = new char[strlen(issueDate)+1];
this->emissionDate = new char[strlen(emissionDate)+1];
this->expiryDate = new char[strlen(expiryDate)+1];
this->expirationDate = new char[strlen(expirationDate)+1];
this->realFileName = new char[1];*/
//Copie de l'information
strcpy(this->no,no);/*
strcpy(this->num,num);
strcpy(this->holder,holder);
strcpy(this->detenteur,detenteur);
strcpy(this->modeOfTransport,modeOfTransport);
strcpy(this->modeDeTransport,modeDeTransport);
strcpy(this->issueDate, issueDate);
strcpy(this->emissionDate,emissionDate);
strcpy(this->expiryDate,expiryDate);
strcpy(this->expirationDate, expirationDate);
this->realFileName[0] = '\0';
this->goodFileName = getGoodName( this->no, this->expiryDate);*/
}

Permit::Permit( char no[], char num[], char holder[], char detenteur[],
char modeOfTransport[], char modeDeTransport[], char issueDate[],
char emissionDate[], char expiryDate[], char expirationDate[],
char realFileName[], char goodFileName[]){
//Allocation dynamique de la memoire
this->no = new char[strlen(no)+1];
this->num = new char[strlen(num)+1];
this->holder = new char[strlen(holder)+1];
this->detenteur = new char[strlen(detenteur)+1];
this->modeOfTransport = new char[strlen(modeOfTransport)+1];
this->modeDeTransport = new char[strlen(modeDeTransport)+1];
this->issueDate = new char[strlen(issueDate)+1];
this->emissionDate = new char[strlen(emissionDate)+1];
this->expiryDate = new char[strlen(expiryDate)+1];
this->expirationDate = new char[strlen(expirationDate)+1];
this->realFileName = new char[strlen(realFileName)+1];
this->goodFileName = new char[strlen(goodFileName)+1];
//Copie de l'information
strcpy(this->no,no);
strcpy(this->num,num);
strcpy(this->holder,holder);
strcpy(this->detenteur,detenteur);
strcpy(this->modeOfTransport,modeOfTransport);
strcpy(this->modeDeTransport,modeDeTransport);
strcpy(this->issueDate, issueDate);
strcpy(this->emissionDate,emissionDate);
strcpy(this->expiryDate,expiryDate);
strcpy(this->expirationDate, expirationDate);
strcpy(this->realFileName,realFileName);
strcpy(this->goodFileName,goodFileName);
}
Permit::Permit(){
//Allocation dynamique de la memoire
this->no = new char[1];
this->num = new char[2];
this->holder = new char[2];
this->detenteur = new char[1];
this->modeOfTransport = new char[1];
this->modeDeTransport = new char[1];
this->issueDate = new char[1];
this->emissionDate = new char[1];
this->expiryDate = new char[1];
this->expirationDate = new char[1];
this->realFileName = new char[1];
this->goodFileName = new char[1];
//Copie de l'information
this->no[0] = '\0';
this->num[0] = '\0';
this->holder[0]= '\0';
this->detenteur[0] = '\0';
this->modeOfTransport[0] = '\0';
this->modeDeTransport[0] = '\0';
this->issueDate[0] = '\0';
this->emissionDate[0] = '\0';
this->expiryDate[0] = '\0';
this->expirationDate[0] = '\0';
this->realFileName[0] = '\0';
this->goodFileName[0] = '\0';
}
Permit::Permit(Permit &permit){
//Realocation de la memoire
this->no = new char[ strlen(permit.no) + 1];
this->num = new char[ strlen(permit.num) + 1];
this->holder = new char[ strlen(permit.holder) + 1];
this->detenteur = new char[ strlen(permit.detenteur) + 1];
this->modeOfTransport = new char[ strlen(permit.modeOfTransport) + 1];
this->modeDeTransport = new char[ strlen(permit.modeDeTransport) + 1];
this->issueDate = new char[ strlen(permit.issueDate) + 1];
this->emissionDate = new char[ strlen(permit.emissionDate) + 1];
this->expiryDate = new char[ strlen(permit.expiryDate) + 1];
this->expirationDate = new char[ strlen(permit.expirationDate) + 1];
this->realFileName = new char[ strlen(permit.realFileName) + 1];
this->goodFileName = new char[ strlen(permit.goodFileName) + 1];
//Copiage de l'information
strcpy(this->no, permit.no);
strcpy(this->num, permit.num);
strcpy(this->holder, permit.holder);
strcpy(this->detenteur, permit.detenteur);
strcpy(this->modeOfTransport, permit.modeOfTransport);
strcpy(this->modeDeTransport, permit.modeDeTransport);
strcpy(this->issueDate, permit.issueDate);
strcpy(this->emissionDate, permit.emissionDate);
strcpy(this->expiryDate, permit.expiryDate);
strcpy(this->expirationDate, permit.expirationDate);
strcpy(this->realFileName, permit.realFileName);
strcpy(this->goodFileName, permit.goodFileName);
}
Permit& Permit::operator=( const Permit &permit){
//Liberation de la memoire allouer dynamiquement
delete []this->no;
delete []this->num;
delete []this->holder;
delete []this->detenteur;
delete []this->modeOfTransport;
delete []this->modeDeTransport;
delete []this->issueDate;
delete []this->emissionDate;
delete []this->expiryDate;
delete []this->expirationDate;
delete []this->realFileName;
delete []this->goodFileName;
//Realocation de la memoire
this->no = new char[ strlen(permit.no) + 1];
this->num = new char[ strlen(permit.num) + 1];
this->holder = new char[ strlen(permit.holder) + 1];
this->detenteur = new char[ strlen(permit.detenteur) + 1];
this->modeOfTransport = new char[ strlen(permit.modeOfTransport) + 1];
this->modeDeTransport = new char[ strlen(permit.modeDeTransport) + 1];
this->issueDate = new char[ strlen(permit.issueDate) + 1];
this->emissionDate = new char[ strlen(permit.emissionDate) + 1];
this->expiryDate = new char[ strlen(permit.expiryDate) + 1];
this->expirationDate = new char[ strlen(permit.expirationDate) + 1];
this->realFileName = new char[ strlen(permit.realFileName) + 1];
this->goodFileName = new char[ strlen(permit.goodFileName) + 1];
//Copiage de l'information
strcpy(this->no, permit.no);
strcpy(this->num, permit.num);
strcpy(this->holder, permit.holder);
strcpy(this->detenteur, permit.detenteur);
strcpy(this->modeOfTransport, permit.modeOfTransport);
strcpy(this->modeDeTransport, permit.modeDeTransport);
strcpy(this->issueDate, permit.issueDate);
strcpy(this->emissionDate, permit.emissionDate);
strcpy(this->expiryDate, permit.expiryDate);
strcpy(this->expirationDate, permit.expirationDate);
strcpy(this->realFileName, permit.realFileName);
strcpy(this->goodFileName, permit.goodFileName);
return *this;
}
//Destructeur
Permit::~Permit(){
delete []this->no;
delete []this->num;
delete []this->holder;
delete []this->detenteur;
delete []this->modeOfTransport;
delete []this->modeDeTransport;
delete []this->issueDate;
delete []this->emissionDate;
delete []this->expiryDate;
delete []this->expirationDate;
delete []this->realFileName;
delete []this->goodFileName;
}

char * Permit::getGoodName( char no[], char expDate[]){
char *tempNo, *goodFileName;
tempNo = new char [ strlen(expDate)+1 ];
strcpy(tempNo,no);
strtok(tempNo,"-");
if( strlen(no)>3 && strlen(expDate)>9){
goodFileName = new char [ strlen(tempNo) + 5 ];
strcpy(goodFileName,tempNo);
strcat(goodFileName,"-");
strncat(goodFileName, &expDate[5], 2);
strncat(goodFileName, &expDate[3], 1);
}
else{
goodFileName = new char[1];
goodFileName[0] = '\0';
}
return goodFileName;
delete []tempNo;
delete []goodFileName;
}

int Permit::setFilePermit(char fName[], char fPath[]){
this->zero("Missing Info");
int nbChBuffer;
bool isBr, isDone=0;
char *fileName, buffer[1026], temp[1026];
cpyData(this->realFileName,fName);
fileName = new char[ strlen(fName) + strlen(fPath) + 5];
strcpy(fileName,fPath);
strcat(fileName,fName);
strcat(fileName,".htm");
fstream fIn;
fIn.open(fileName, ios::in);
delete []fileName;
if( !fIn.is_open()){
system("cls");
cout << "Error - Missing File(s)\n";
system("pause");
exit(1);
}
while( !fIn.eof() && !isDone){
isBr=0;
fIn.getline(buffer,1025);
isBr = clString(buffer);
while(!isBr && !fIn.eof()){
fIn.getline(temp,1025);
strcat(buffer," ");
strcat(buffer,temp);
isBr = clString(buffer);
}
for( nbChBuffer=0 ; nbChBuffer<strlen(buffer) ; nbChBuffer++ ){
if(strnicmp(&buffer[nbChBuffer],"Permit No",strlen("Permit No"))==0){
strcpy(temp,&buffer[nbChBuffer + strlen("Permit No")]);
clFrstCh(temp);
cpyData(this->no,temp);
}
if(strnicmp(&buffer[nbChBuffer],"N° du permis",strlen("N° du permis"))==0){
strcpy(temp,&buffer[nbChBuffer + strlen("N° du permis")]);
clFrstCh(temp);
cpyData(this->num,temp);
}
if(strnicmp(&buffer[nbChBuffer],"Permit Holder",strlen("Permit Holder"))==0){
strcpy(temp,&buffer[nbChBuffer + strlen("Permit Holder")]);
clFrstCh(temp);
cpyData(this->holder,temp);
}
if(strnicmp(&buffer[nbChBuffer],"Détenteur du permis",strlen("Détenteur du permis"))==0){
strcpy(temp,&buffer[nbChBuffer + strlen("Détenteur du permis")]);
clFrstCh(temp);
cpyData(this->detenteur,temp);
}
if(strnicmp(&buffer[nbChBuffer],"Mode of Transport",strlen("Mode of Transport"))==0){
strcpy(temp,&buffer[nbChBuffer + strlen("Mode of Transport")]);
clFrstCh(temp);
cpyData(this->modeOfTransport,temp);
}
if(strnicmp(&buffer[nbChBuffer],"Mode de transport",strlen("Mode de transport"))==0){
strcpy(temp,&buffer[nbChBuffer + strlen("Mode de transport")]);
clFrstCh(temp);
cpyData(this->modeDeTransport,temp);
}
if(strnicmp(&buffer[nbChBuffer],"Issue Date",strlen("Issue Date"))==0){
strcpy(temp,&buffer[nbChBuffer + strlen("Issue Date")]);
clFrstCh(temp);
cpyData(this->issueDate,temp);
}
if(strnicmp(&buffer[nbChBuffer],"Date d'émission",strlen("Date d’émission"))==0){
strcpy(temp,&buffer[nbChBuffer + strlen("Date d’émission")]);
clFrstCh(temp);
cpyData(this->emissionDate,temp);
}
if(strnicmp(&buffer[nbChBuffer],"Expiry Date",strlen("Expiry Date"))==0){
strcpy(temp,&buffer[nbChBuffer + strlen("Expiry Date")]);
clFrstCh(temp);
cpyData(this->expiryDate,temp);
}
if(strnicmp(&buffer[nbChBuffer],"Date d'expiration",strlen("Date d’expiration"))==0){
strcpy(temp,&buffer[nbChBuffer + strlen("Date d’expiration")]);
clFrstCh(temp);
cpyData(this->expirationDate,temp);
}
if(strnicmp(&buffer[nbChBuffer],"CONDITIONS",strlen("CONDITIONS"))==0){
isDone=1;
}
}
}
fIn.close();
return 0;
}
int Permit::cpyData( char text[], const char newText[]){
char *tempNewText;
int newStrLen = strlen(newText) + 1;
tempNewText = new char [ newStrLen ];
strcpy(tempNewText, newText);
//Copie temporaire du Permit
Permit tempPermit(*this);
//Liberation de la memoire allouer dynamiquement
this->~Permit();
//Reallocation de la memoire
if(this->no==text){
this->no = new char[ newStrLen ];
strcpy(this->no,tempNewText);
}
else{
this->no = new char[ strlen(tempPermit.no) + 1 ];
strcpy(this->no,tempPermit.no);
}
if(this->num==text){
this->num = new char[ newStrLen ];
strcpy(this->num,tempNewText);
}
else{
this->num = new char[ strlen(tempPermit.num) + 1 ];
strcpy(this->num,tempPermit.num);
}
if(this->holder==text){
this->holder = new char[ newStrLen ];
strcpy(this->holder,tempNewText);
}
else{
this->holder = new char[ strlen(tempPermit.holder) + 1 ];
strcpy(this->holder,tempPermit.holder);
}
if(this->detenteur==text){
this->detenteur = new char[ newStrLen ];
strcpy(this->detenteur,tempNewText);
}
else{
this->detenteur = new char[ strlen(tempPermit.detenteur) + 1 ];
strcpy(this->detenteur,tempPermit.detenteur);
}
if(this->modeOfTransport==text){
this->modeOfTransport = new char[ newStrLen ];
strcpy(this->modeOfTransport,tempNewText);
}
else{
this->modeOfTransport = new char[ strlen(tempPermit.modeOfTransport) + 1 ];
strcpy(this->modeOfTransport,tempPermit.modeOfTransport);
}
if(this->modeDeTransport==text){
this->modeDeTransport = new char[ newStrLen ];
strcpy(this->modeDeTransport,tempNewText);
}
else{
this->modeDeTransport = new char[ strlen(tempPermit.modeDeTransport) + 1 ];
strcpy(this->modeDeTransport,tempPermit.modeDeTransport);
}
if(this->issueDate==text){
this->issueDate = new char[ newStrLen ];
strcpy(this->issueDate,tempNewText);
}
else{
this->issueDate = new char[ strlen(tempPermit.issueDate) + 1 ];
strcpy(this->issueDate,tempPermit.issueDate);
}
if(this->emissionDate==text){
this->emissionDate = new char[ newStrLen ];
strcpy(this->emissionDate,tempNewText);
}
else{
this->emissionDate = new char[ strlen(tempPermit.emissionDate) + 1 ];
strcpy(this->emissionDate,tempPermit.emissionDate);
}
if(this->expiryDate==text){
this->expiryDate = new char[ newStrLen ];
strcpy(this->expiryDate,tempNewText);
}
else{
this->expiryDate = new char[ strlen(tempPermit.expiryDate) + 1 ];
strcpy(this->expiryDate,tempPermit.expiryDate);
}
if(this->expirationDate==text){
this->expirationDate = new char[ newStrLen ];
strcpy(this->expirationDate,tempNewText);
}
else{
this->expirationDate = new char[ strlen(tempPermit.expirationDate) + 1 ];
strcpy(this->expirationDate,tempPermit.expirationDate);
}
if(this->realFileName==text){
this->realFileName = new char[ newStrLen ];
strcpy(this->realFileName,tempNewText);
}
else{
this->realFileName = new char[ strlen(tempPermit.realFileName) + 1 ];
strcpy(this->realFileName,tempPermit.realFileName);
}
if(this->goodFileName==text){
this->goodFileName = new char[ newStrLen ];
strcpy(this->goodFileName,tempNewText);
}
else{
this->goodFileName = new char[ strlen(tempPermit.goodFileName) + 1 ];
strcpy(this->goodFileName,tempPermit.goodFileName);
}
//Liberation de la memoire temporaire
delete []tempNewText;
//Retour du nombre de caractere
return newStrLen;
}
int Permit::catData( char text[], const char newText[]){
char *tempNewText;
int newStrLen = strlen(newText) + 1;
tempNewText = new char [ newStrLen ];
strcpy(tempNewText, newText);
//Copie temporaire du Permit
Permit tempPermit(*this);
//Liberation de la memoire allouer dynamiquement
this->~Permit();
//Reallocation de la memoire
if(this->no==text){
this->no = new char[ newStrLen + strlen(tempPermit.no) ];
strcpy(this->no,tempPermit.no);
strcat(this->no,tempNewText);
}
else{
this->no = new char[ strlen(tempPermit.no) + 1 ];
strcpy(this->no,tempPermit.no);
}
if(this->num==text){
this->num = new char[ newStrLen + strlen(tempPermit.num) ];
strcpy(this->num,tempPermit.num);
strcat(this->num,tempNewText);
}
else{
this->num = new char[ strlen(tempPermit.num) + 1 ];
strcpy(this->num,tempPermit.num);
}
if(this->holder==text){
this->holder = new char[ newStrLen + strlen(tempPermit.holder) ];
strcpy(this->holder,tempPermit.holder);
strcat(this->holder,tempNewText);
}
else{
this->holder = new char[ strlen(tempPermit.holder) + 1 ];
strcpy(this->holder,tempPermit.holder);
}
if(this->detenteur==text){
this->detenteur = new char[ newStrLen + strlen(tempPermit.detenteur) ];
strcpy(this->detenteur,tempPermit.detenteur);
strcat(this->detenteur,tempNewText);
}
else{
this->detenteur = new char[ strlen(tempPermit.detenteur) + 1 ];
strcpy(this->detenteur,tempPermit.detenteur);
}
if(this->modeOfTransport==text){
this->modeOfTransport = new char[ newStrLen + strlen(tempPermit.modeOfTransport) ];
strcpy(this->modeOfTransport,tempPermit.modeOfTransport);
strcat(this->modeOfTransport,tempNewText);
}
else{
this->modeOfTransport = new char[ strlen(tempPermit.modeOfTransport) + 1 ];
strcpy(this->modeOfTransport,tempPermit.modeOfTransport);
}
if(this->modeDeTransport==text){
this->modeDeTransport = new char[ newStrLen + strlen(tempPermit.modeDeTransport) ];
strcpy(this->modeDeTransport,tempPermit.modeDeTransport);
strcat(this->modeDeTransport,tempNewText);
}
else{
this->modeDeTransport = new char[ strlen(tempPermit.modeDeTransport) + 1 ];
strcpy(this->modeDeTransport,tempPermit.modeDeTransport);
}
if(this->issueDate==text){
this->issueDate = new char[ newStrLen + strlen(tempPermit.issueDate) ];
strcpy(this->issueDate,tempPermit.issueDate);
strcat(this->issueDate,tempNewText);
}
else{
this->issueDate = new char[ strlen(tempPermit.issueDate) + 1 ];
strcpy(this->issueDate,tempPermit.issueDate);
}
if(this->emissionDate==text){
this->emissionDate = new char[ newStrLen + strlen(tempPermit.emissionDate) ];
strcpy(this->emissionDate,tempPermit.emissionDate);
strcat(this->emissionDate,tempNewText);
}
else{
this->emissionDate = new char[ strlen(tempPermit.emissionDate) + 1 ];
strcpy(this->emissionDate,tempPermit.emissionDate);
}
if(this->expiryDate==text){
this->expiryDate = new char[ newStrLen + strlen(tempPermit.expiryDate) ];
strcpy(this->expiryDate,tempPermit.expiryDate);
strcat(this->expiryDate,tempNewText);
}
else{
this->expiryDate = new char[ strlen(tempPermit.expiryDate) + 1 ];
strcpy(this->expiryDate,tempPermit.expiryDate);
}
if(this->expirationDate==text){
this->expirationDate = new char[ newStrLen + strlen(tempPermit.expirationDate) ];
strcpy(this->expirationDate,tempPermit.expirationDate);
strcat(this->expirationDate,tempNewText);
}
else{
this->expirationDate = new char[ strlen(tempPermit.expirationDate) + 1 ];
strcpy(this->expirationDate,tempPermit.expirationDate);
}
if(this->realFileName==text){
this->realFileName = new char[ newStrLen + strlen(tempPermit.realFileName) ];
strcpy(this->realFileName,tempPermit.realFileName);
strcat(this->realFileName,tempNewText);
}
else{
this->realFileName = new char[ strlen(tempPermit.realFileName) + 1 ];
strcpy(this->realFileName,tempPermit.realFileName);
}
if(this->goodFileName==text){
this->goodFileName = new char[ newStrLen + strlen(tempPermit.goodFileName) ];
strcpy(this->goodFileName,tempPermit.goodFileName);
strcat(this->goodFileName,tempNewText);
}
else{
this->goodFileName = new char[ strlen(tempPermit.goodFileName) + 1 ];
strcpy(this->goodFileName,tempPermit.goodFileName);
}
//Liberation de la memoire temporaire
delete []tempNewText;
//Retour du nombre de caractere
return newStrLen;
}
void Permit::afficher(){
cout << "No : " << this->no << endl
<< "Num : " << this->num << endl
<< "Holder : " << this->holder << endl
<< "Detenteur : " << this->detenteur << endl
<< "Mode of : " << this->modeOfTransport << endl
<< "Mode de : " << this->modeDeTransport << endl
<< "Issue : " << this->issueDate << endl
<< "Emission : " << this->emissionDate << endl
<< "Expiry : " << this->expiryDate << endl
<< "Expiration : " << this->expirationDate << endl
<< "Real File Name : " << this->realFileName << endl
<< "Good File Name : " << this->goodFileName << endl;
}
void Permit::zero(const char text[]){
int newStrLen = strlen(text) + 1;
//Liberation de la memoire allouer dynamiquement
delete []this->no;
delete []this->num;
delete []this->holder;
delete []this->detenteur;
delete []this->modeOfTransport;
delete []this->modeDeTransport;
delete []this->issueDate;
delete []this->emissionDate;
delete []this->expiryDate;
delete []this->expirationDate;
delete []this->realFileName;
delete []this->goodFileName;
//Realocation de la memoire
this->no = new char[ newStrLen ];
this->num = new char[ newStrLen ];
this->holder = new char[ newStrLen ];
this->detenteur = new char[ newStrLen ];
this->modeOfTransport = new char[ newStrLen ];
this->modeDeTransport = new char[ newStrLen ];
this->issueDate = new char[ newStrLen ];
this->emissionDate = new char[ newStrLen ];
this->expiryDate = new char[ newStrLen ];
this->expirationDate = new char[ newStrLen ];
this->realFileName = new char[ newStrLen ];
this->goodFileName = new char[ newStrLen ];
//Copie de base
strcpy( this->no , text);
strcpy( this->num , text);
strcpy( this->holder , text);
strcpy( this->detenteur , text);
strcpy( this->modeOfTransport , text);
strcpy( this->modeDeTransport , text);
strcpy( this->issueDate , text);
strcpy( this->emissionDate , text);
strcpy( this->expiryDate , text);
strcpy( this->expirationDate , text);
strcpy( this->realFileName , text);
strcpy( this->goodFileName , text);
}
ofstream& operator<<( ofstream &out, const Permit &p ){
out << "\t\n"
<< "\t\t<no>" << p.no << "</no>\n"
<< "\t\t<num>" << p.num << "</num>\n"
<< "\t\t<holder>" << p.holder << "</holder>\n"
<< "\t\t<detenteur>" << p.detenteur << "</detenteur>\n"
<< "\t\t<modeOfTransport>" << p.modeOfTransport << "</modeOfTransport>\n"
<< "\t\t<modeDeTransport>" << p.modeDeTransport << "</modeDeTransport>\n"
<< "\t\t" << p.issueDate << "\n"
<< "\t\t" << p.emissionDate << "\n"
<< "\t\t<expiryDate>" << p.expiryDate << "</expiryDate>\n"
<< "\t\t<expirationDate>" << p.expirationDate << "</expirationDate>\n"
<< "\t\t<realFileName>" << p.realFileName << "</realFileName>\n"
<< "\t\t<goodFileName>" << p.goodFileName << "</goodFileName>\n"
<< "\t

\n";
return out;
}
ostream& operator<<( ostream &out, const Permit &p ){
out << "No : " << p.no << endl
<< "Num : " << p.num << endl
<< "Holder : " << p.holder << endl
<< "Detenteur : " << p.detenteur << endl
<< "Mode of : " << p.modeOfTransport << endl
<< "Mode de : " << p.modeDeTransport << endl
<< "Issue : " << p.issueDate << endl
<< "Emission : " << p.emissionDate << endl
<< "Expiry : " << p.expiryDate << endl
<< "Expiration : " << p.expirationDate << endl
<< "Real File Name : " << p.realFileName << endl
<< "Good File Name : " << p.goodFileName << endl;
return out;
}
0
Rejoignez-nous