boujour,
voila j'aurais voulu savoir comment faire pour
faire un test argument si il commence par . ou /:
avec l'utilisation de strncmp.
sinon autre solution
merci d'avance
boujour,
voila j'aurais voulu savoir comment faire pour
faire un test argument si il commence par . ou /:
avec l'utilisation de strncmp.
sinon autre solution
merci d'avance
Pas besoin de strncmp() pour cela. Si ton argument est une chaine de caractères, il te suffit de tester:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 if (mon_argument[0] == '.') { /*...*/ } else if (mon argument[0] == '/') { /*...*/ } else { /*...*/ }
Thierry
"The most important thing in the kitchen is the waste paper basket and it needs to be centrally located.", Donald Knuth
"If the only tool you have is a hammer, every problem looks like a nail.", probably Abraham Maslow
FAQ-Python FAQ-C FAQ-C++
+
En faite s'est pour mon program ls - lR que je suis entrain de faire
et je voudrais faire un test aui me renverrai une erreur si l'argument n'est pas . ou /
Voici un exemple:
Sous forme d'un programme exécutable, on obtient:
Thierry
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include <stdio.h> #include <stdlib.h> void usage(void) { printf("Usage: mon_programme chemin\n"); } int main(int argc, char *argv[]) { int ret = 0; if (argc == 2) { int c = argv[1][0]; if (c == '.') { printf("Chemin relatif!\n"); } else if (c == '/') { printf("Chemin absolu!\n"); } else { /* -tc- Erreur */ usage(); ret = EXIT_FAILURE; } } else { usage(); ret = EXIT_FAILURE; } return ret; }
"The most important thing in the kitchen is the waste paper basket and it needs to be centrally located.", Donald Knuth
"If the only tool you have is a hammer, every problem looks like a nail.", probably Abraham Maslow
FAQ-Python FAQ-C FAQ-C++
+
Ou tout simplement :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 switch (mon argument[0]) { case '.' : /*...*/ break; case '/' : /*...*/ break; default: ; /*...*/ }
"The most important thing in the kitchen is the waste paper basket and it needs to be centrally located.", Donald Knuth
"If the only tool you have is a hammer, every problem looks like a nail.", probably Abraham Maslow
FAQ-Python FAQ-C FAQ-C++
+
Partager