-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfonctions.cpp
More file actions
118 lines (95 loc) · 2.88 KB
/
fonctions.cpp
File metadata and controls
118 lines (95 loc) · 2.88 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <fstream>
#include <string>
#include "header.h"
#include <stdlib.h>
#define ISOPTION true
#define NOTOPTION false
using namespace std;
void help(void)
{
cout << "Utilisation : harmo [OPTION value]... " << endl << endl
<< "Cacule le nieme nombre de la suite Harmonique n etant fournie en entré ou les nombres " << endl
<< "de la suite dans un enterval d'indice, le plus petit indice etant 0, le resultat peut etre stocker dans un fichier" << endl
<< " de taille non nulle de caractères délimités par une espace." << endl << endl
<< "Les options sont : " << endl
<< " -F, --file specifie le fichier de sortie (mode d'ouverture ecriture) " << endl
<< " --space= pour preciser le separateur par defaut, c'est la tabulation" << endl
<< " --help afficher l'aide et quitter" << endl;
}
bool active_option(unsigned char option, int& i, int argc ,char** argv, string& file )
{
switch (option)
{
case 'F':
if( i == argc)
{
cerr << "max : usage option value" << endl;
exit(EXIT_FAILURE);
}
else
{
file = argv[++i];
}
break;
default:
return NOTOPTION;
}
return ISOPTION;
}
bool active_long_option(string option, int& i, int argc ,char** argv, string& file)
{
if(option.compare((string)"--file") == EQUAL)
{
if( i == argc)
{
cerr << "max : usage option value" << endl;
exit(EXIT_FAILURE);
}
else
{
file = argv[++i];
}
return ISOPTION;
}
return NOTOPTION;
}
double convertion(char * chaine)
{
unsigned long i(0), j(1);
double nombre = 0;
short signe = POSITIF;
bool isDecimal = false;
if(chaine[0] == TIRET)
{
signe = NEGATIF;
i++;
}
while(chaine[i] != '\0'){
if(chaine[i] == '.' || chaine[i] == ','){
isDecimal = true;
i++;
break;
}
if( chaine[i] > 47 && chaine[i] < 59){
nombre = nombre * 10*i + chaine[i] - 48;
}else{
cerr <<"max : " << chaine << " nombre invalide" << endl;
exit(EXIT_FAILURE);
}
i++;
}
if(isDecimal){
while(chaine[i] != '\0'){
if( chaine[i] > 47 && chaine[i] < 59){
nombre = nombre + (double)(chaine[i] - 48)/( 10*j);
}else{
cerr <<"max : " << chaine << " is not a number" << endl;
exit(EXIT_FAILURE);
}
i++;
j++;
}
}
return nombre * signe;
}