nous allons présenter la librairie qui va permettre de gérer les chaines de caractères.
C'est l'occasion de voir comment utiliser une librairie mise à disposition
#include <string.h>
Le fichier source , string.c est disponible sur github de Linus Torvald
string.h(3avr) avr-libc string.h(3avr)
NAME
string.h
SYNOPSIS
Macros
#define _FFS(x)
Functions
int ffs (int __val)
int ffsl (long __val)
__extension__ int ffsll (long long __val)
void * memccpy (void *, const void *, int, size_t)
void * memchr (const void *, int, size_t) __ATTR_PURE__
int memcmp (const void *, const void *, size_t) __ATTR_PURE__
void * memcpy (void *, const void *, size_t)
void * memmem (const void *, size_t, const void *, size_t) __ATTR_PURE__
void * memmove (void *, const void *, size_t)
void * memrchr (const void *, int, size_t) __ATTR_PURE__
void * memset (void *, int, size_t)
char * strcat (char *, const char *)
char * strchr (const char *, int) __ATTR_PURE__
char * strchrnul (const char *, int) __ATTR_PURE__
int strcmp (const char *, const char *) __ATTR_PURE__
char * strcpy (char *, const char *)
int strcasecmp (const char *, const char *) __ATTR_PURE__
char * strcasestr (const char *, const char *) __ATTR_PURE__
.....
strlen(3) Library Functions Manual strlen(3)
NAME
strlen - calculate the length of a string
LIBRARY
Standard C library (libc, -lc)
SYNOPSIS
#include <string.h>
size_t strlen(const char *s);
DESCRIPTION
The strlen() function calculates the length of the string pointed to by s, excluding the terminating null byte ('\0').
RETURN VALUE
The strlen() function returns the number of bytes in the string pointed to by s.
ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7).
┌──────────────────────────────────────────────────────────────────────────────────────────────────────┬───────────────┬─────────┐
│Interface │ Attribute │ Value │
├──────────────────────────────────────────────────────────────────────────────────────────────────────┼───────────────┼─────────┤
│strlen() │ Thread safety │ MT-Safe │
└──────────────────────────────────────────────────────────────────────────────────────────────────────┴───────────────┴─────────┘
source de la fonction strlen en C par Linus Torvald
size_t strlen(const char *s)
{
const char *sc;
for (sc = s; *sc != '\0'; ++sc)
/* nothing */;
return sc - s;
}
strcpy(3) Library Functions Manual strcpy(3)
NAME
stpcpy, strcpy, strcat - copy or catenate a string
LIBRARY
Standard C library (libc, -lc)
SYNOPSIS
#include <string.h>
char *stpcpy(char *restrict dst, const char *restrict src);
char *strcpy(char *restrict dst, const char *restrict src);
char *strcat(char *restrict dst, const char *restrict src);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
stpcpy():
Since glibc 2.10:
_POSIX_C_SOURCE >= 200809L
Before glibc 2.10:
_GNU_SOURCE
DESCRIPTION
stpcpy()
strcpy()
These functions copy the string pointed to by src, into a string at the buffer pointed to by dst. The programmer is re‐
sponsible for allocating a destination buffer large enough, that is, strlen(src) + 1. For the difference between the two
strcmp(3) Library Functions Manual strcmp(3)
NAME
strcmp, strncmp - compare two strings
LIBRARY
Standard C library (libc, -lc)
SYNOPSIS
#include <string.h>
int strcmp(const char *s1, const char *s2);
int strncmp(const char s1[.n], const char s2[.n], size_t n);
DESCRIPTION
The strcmp() function compares the two strings s1 and s2. The locale is not taken into account (for a locale-aware comparison,
see strcoll(3)). The comparison is done using unsigned characters.
strcmp() returns an integer indicating the result of the comparison, as follows:
• 0, if the s1 and s2 are equal;
• a negative value if s1 is less than s2;
• a positive value if s1 is greater than s2.
The strncmp() function is similar, except it compares only the first (at most) n bytes of s1 and s2.