Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cours_prog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
yassin.elhakoun
cours_prog
Commits
a2291699
Commit
a2291699
authored
5 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
added command line
parent
9b862bf3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Makefile
+4
-1
4 additions, 1 deletion
Makefile
ligne_commande.md
+83
-0
83 additions, 0 deletions
ligne_commande.md
with
87 additions
and
1 deletion
Makefile
+
4
−
1
View file @
a2291699
...
@@ -19,7 +19,7 @@ HTMLOPTIONS += -t html5
...
@@ -19,7 +19,7 @@ HTMLOPTIONS += -t html5
HTMLOPTIONS
+=
-c
css/tufte-css/tufte.css
HTMLOPTIONS
+=
-c
css/tufte-css/tufte.css
HTMLOPTIONS
+=
--self-contained
HTMLOPTIONS
+=
--self-contained
all
:
strings.pdf tests_assertions.pdf make.pdf base_3.pdf base_2.pdf base_1.pdf intro.pdf index.html
all
:
ligne_commande.pdf
strings.pdf tests_assertions.pdf make.pdf base_3.pdf base_2.pdf base_1.pdf intro.pdf index.html
intro.pdf
:
intro.md metadata.yaml
intro.pdf
:
intro.md metadata.yaml
pandoc
$(
PDFOPTIONS
)
-o
$@
$^
pandoc
$(
PDFOPTIONS
)
-o
$@
$^
...
@@ -42,6 +42,9 @@ tests_assertions.pdf: tests_assertions.md metadata.yaml
...
@@ -42,6 +42,9 @@ tests_assertions.pdf: tests_assertions.md metadata.yaml
strings.pdf
:
strings.md metadata.yaml
strings.pdf
:
strings.md metadata.yaml
pandoc
$(
PDFOPTIONS
)
-o
$@
$^
pandoc
$(
PDFOPTIONS
)
-o
$@
$^
ligne_commande.pdf
:
ligne_commande.md metadata.yaml
pandoc
$(
PDFOPTIONS
)
-o
$@
$^
index.html
:
index.md
index.html
:
index.md
pandoc
-s
$(
OPTIONS
)
$(
HTMLOPTIONS
)
-o
$@
$<
pandoc
-s
$(
OPTIONS
)
$(
HTMLOPTIONS
)
-o
$@
$<
...
...
This diff is collapsed.
Click to expand it.
ligne_commande.md
0 → 100644
+
83
−
0
View file @
a2291699
% La ligne de commande
% Inspirés des slides de F. Glück
% 16 octobre 2019
# Point d'entrée d'un programme
-
Le point d'entrée est la fonction
`main()`
{.C}.
-
Elle peut être déclarée de 4 façon différentes:
1.
`void main()`
{.C}.
2.
`int main()`
{.C}.
3.
`void main(int argc, char **argv)`
{.C}.
4.
`int main(int argc, char **argv)`
{.C}.
-
`argc`
{.C} est le nombre d'arguments passés à la ligne de commade:
**le premier est celui du programme lui-même**
.
-
`argv`
{.C} est un tableau de chaînes de caractères passés sur la ligne de commande.
# Exemple d'utilisation
Pour la fonction dans le programme
`prog`
```
C
int main(int argc, char **argv)
```
Pour l'exécution suivante on a
```
bash
$
./prog
-b
50 file.txt
```
```
C
argc == 4
argv[0] == "prog"
argv[1] == "-b"
argv[2] == "50"
argv[3] == "file.txt"
```
# Conversion des arguments
-
Les arguments sont toujours stockés comme des
**chaînes de caractère**
.
-
Peu pratique si on veut manipuler des valeurs numériques.
-
Fonctions pour faire des conversions:
```C
int atoi(const char *nptr);
long atol(const char *nptr);
long long atoll(const char *nptr);
double atof(const char *nptr);
int snprintf(char *str, size_t size,
const char *format, ...);
// str: buffer, size: taille en octets max à copier,
// format: cf printf(), ret: nombre de char lus
```
# Exemple d'utilisation
\f
ootnotesize
```
C
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
int main(int argc, char **argv) {
if (argc != 3) {
char *progname = basename(argv[0]);
fprintf(stderr, "usage: %s name age\n", progname);
return EXIT_FAILURE;
}
char *name = argv[1];
int age = atoi(argv[2]);
printf("Hello %s, you are %d years old.\n", name, age);
return EXIT_SUCCESS;
}
```
```
bash
$
./prog Paul 29
Hello Paul, you are 29 years old.
```
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment