Vous êtes sur la page 1sur 44

PLAN DETAILLE DU COURS

Programmation en langage C
- Les instructions du contrôle (suite)
- Les tableaux à une dimension
- Les chaines de caractères
- Les types composés
- Les fonctions
- Les pointeurs
- Les tableaux à deux dimensions
- Les algorithmes de tri
LES CHAINES DE CARACTERES

• En langage C, il n’existe pas de type de variable pour les


chaînes de caractères comme pour les entiers ou les
caractères.
• Les chaînes sont stockées dans un tableau de caractères
dont la fin est marquée par le caractères ‘\0’.

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 2


LES CHAINES DE CARACTERES

• La chaîne est stockée dans un tableau de caractères


dont la fin est marquée par le caractères ‘\0’.
Programmation en C 1A-IIIA Année Universitaire : 2022-2023 3
LES CHAINES DE CARACTERES

Lecture

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 4


LES CHAINES DE CARACTERES
Déclaration & Initialisation

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 5


LES CHAINES DE CARACTERES
Déclaration & Initialisation

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 6


LES CHAINES DE CARACTERES
Déclaration & Initialisation : Exemples

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 7


LES CHAINES DE CARACTERES
Déclaration & Initialisation : Exemples

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 8


LES CHAINES DE CARACTERES

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 9


LES CHAINES DE CARACTERES
Déclaration & Initialisation

Comment affecter une autre valeur dans la variable chaine ?


Programmation en C 1A-IIIA Année Universitaire : 2022-2023 10
LES CHAINES DE CARACTERES
Déclaration & Initialisation
Affectation

Char [4]
n est un caractère

Case 6 n’existe pas


Programmation en C 1A-IIIA Année Universitaire : 2022-2023 11
LES CHAINES DE CARACTERES
Déclaration & Initialisation
• En C, il n’existe pas de type de variable pour les chaînes de
caractères comme pour les entiers ou les caractères.
• Les chaînes sont stockées dans un tableau de caractères
dont la fin est marquée par le caractères ‘\0’.
• Cela signifie qu’une chaîne de n caractères occupe en
mémoire un emplacement de n+1 octets.
• En mémoire, la chaine « Hello » est représentée comme
suit:
Programmation en C 1A-IIIA Année Universitaire : 2022-2023 12
LES CHAINES DE CARACTERES
Déclaration & Initialisation

• Une chaîne de caractères peut être déclarée et initialisée de


plusieurs manières, la plus simple est :

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 13


LES CHAINES DE CARACTERES

Lecture

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 14


LES CHAINES DE CARACTERES
Affichage & Lecture

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 15


LES CHAINES DE CARACTERES
Affichage : A tester sur vos machines

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 16


LES CHAINES DE CARACTERES
Lecture : A tester sur vos machines

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 17


LES CHAINES DE CARACTERES
Lecture : A tester sur vos machines

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 18


LES CHAINES DE CARACTERES
Lecture : A tester sur vos machines

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 19


LES CHAINES DE CARACTERES
Affichage & Lecture

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 20


LES CHAINES DE CARACTERES
Affichage & Lecture

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 21


LES CHAINES DE CARACTERES
Affichage & Lecture

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 22


LES CHAINES DE CARACTERES
Affichage & Lecture

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 23


LES CHAINES DE CARACTERES
Affichage & Lecture

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 24


LES CHAINES DE CARACTERES
Affichage & Lecture

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 25


LES CHAINES DE CARACTERES

Lecture

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 26


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes :

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 27


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strlen()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 28


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strncpy()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 29


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strcat()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 30


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strncat()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 31


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strcmp()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 32


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strcmp()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 33


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strncat()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 34


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strncat()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 35


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strcmp()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 36


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strcmp()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 37


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strchr()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 38


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strrchr()

Remarque : la fonction strchr() est très proche de la fonction strrchr(). La différence réside
dans le fait que strchr() renvoi la position de la première occurrence du caractère
recherché alors que strrchr() renvoi la dernière occurrence (recherche par la droite : r
signifiant right).
Programmation en C 1A-IIIA Année Universitaire : 2022-2023 39
LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strstr()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 40


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strrev()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 41


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strupr()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 42


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes : strlwr()

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 43


LES CHAINES DE CARACTERES
Fonctions sur les Chaînes :

Programmation en C 1A-IIIA Année Universitaire : 2022-2023 44

Vous aimerez peut-être aussi