String.h: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Fripp (discussione | contributi)
Nuova pagina; testo: '{{T|lingua=inglese|argomento=informatica|data=maggio 2007}} {{libreria standard C}} '''string.h''' è l'header file della libreria standard del C che contiene definiz...'
 
m WPCleaner v2.05 - Fixed using WP:WPCleaner (Errori comuni)
 
(82 versioni intermedie di 52 utenti non mostrate)
Riga 1:
{{titolo minuscolo}}{{libreria standard C}}
{{T|lingua=inglese|argomento=informatica|data=maggio 2007}}
{{libreria standard C}}
 
'''string.h''' è l'[[header file]] della [[libreria standard del C]] che contiene definizioni di macro, costanti e dichiarazioni di funzioni e tipi usati non solo nella manipolazione delle stringhe ma anche nella manipolazione della memoria.
 
Le funzioni dichiarate in ''string.h'' sono molto popolari ed essendo parte della libreria standard del C, il loro funzionamento è garantito su ogni piattaforma che supporta il linguaggio C. Tuttavia, l'esistenza di alcuni problemi di sicurezza con queste funzioni, come per esempio problemi di [[buffer overflow]], portano i programmatori a scegliere delle varianti più sicure ma meno portabili. Inoltre le funzioni in questione lavorano solamente con caratteri [[ASCII]] o con un set di caratteri che lo estende in modo compatibile come l'[[ISO 8859-1]]. La gestione di stringhe non compatibili con l'ASCII viene generalmente risolto con l'uso della libreria <code>[[wchar.h]]</code>.
 
==Costanti e tipi==
<!--
Also, the string functions only work with [[ASCII]] or character sets that extend ASCII in a compatible manner such as [[ISO-8859-1]]; multibyte ASCII-compatible character sets such as [[UTF-8]] will work with the caveat that string "length" is to be interpreted as the count of bytes in the string rather than the count of [[Unicode]] characters. Non-ASCII compatible string handling is generally achieved through <code>[[wchar.h]]</code>.
 
==Constants and types==
 
{| class="wikitable"
|-
! NameNome !! NotesDescrizione
|-
|<code>NULL</code> || Una macro che rappresenta la costante [[Puntatore (programmazione)#Il puntatore null|puntatore nullo]]; in altre parole, una costante che rappresenta un valore che è garantito essere l'indirizzo di una posizione '''non''' valida nella memoria.
|<code>NULL</code> || a macro expanding to the [[null pointer]] constant; that is, a constant representing a pointer value which is guaranteed '''not''' to be a valid address of an object in memory.
|-
|<code>size_t</code> || anUn unsignedintero [[integer]]senza typesegno whichrestituito is the type of the result of thedell'operatore <code>[[sizeof]]</code> operator.
|}
 
==FunctionsFunzioni==
 
{| class="wikitable"
|-
! NameNome !! NotesDescrizione
|-
|<code>void *[[memcpy]](void *dest, const void *src, size_t n);</code>
|copiesCopia n bytes betweentra twodue memoryaree areas,di whichmemoria mustche notnon overlapdevono sovrapporsi.
|-
|<code>void *[[memmove]](void *dest, const void *src, size_t n);</code>
|copiesCopia n bytes betweentra twodue memoryaree areasdi memoria; unlikea withdifferenza di <code>memcpy</code> thele aree di areasmemoria maypossono overlapsovrapporsi.
|-
|<code>void *[[memchr]](const void *s, int c, size_t n);</code>
|Ritorna un puntatore alla prima occorrenza di ''c'' in ''s'', o NULL se ''c'' non compare tra i primi ''n'' caratteri di ''s''.
|returns a pointer to the first occurrence of c in the first n bytes of s, or NULL if not found
|-
|<code>int [[memcmp]](const void *s1, const void *s2, size_t n);</code>
|Confronta i primi ''n'' caratteri di ''s1'' con ''s2''.
|compares the first n characters of two memory areas
|-
|<code>void *[[memset]](void *s, int c, size_t n);</code>
|Colloca ''c'' nei primi ''n'' caratteri di ''s''.
|overwrites a memory area with a byte pattern
|-
|<code>char *[[strcat]](char *dest, const char *src);</code>
|Concatena ''src'' alla stringa ''dest''.
|appends the string src to dest
|-
|<code>'''char *[[strncat]](char *dest, const char *src, size_t n);'''</code>
|Concatena al massimo ''n'' caratteri ''src'' alla stringa ''dest''.
|appends at most n characters of the string src to dest
|-
|<code>char *[[strchr]](const char *s, int c);</code>
|Restituisce un puntatore alla prima occorrenza di ''c'' in ''s''.
|locates a character in a string, searching from the beginning
|-
|<code>char *[[strrchr]](const char *s, int c);</code>
|Restituisce un puntatore all'ultima occorrenza di ''c'' in ''s''.
|locates a character in a string, searching from the end
|-
|<code>int [[strcmp]](const char *s1, const char *s2);</code>
|Confronta la stringa ''s1'' con ''s2''.
|compares two strings numerically
|-
|<code>int [[strncmp]](const char *, const char *, size_t);</code>
|Confronta al massimo ''n'' caratteri della stringa ''s1'' con ''s2''.
|compares up to the first n bytes of two strings numerically
|-
|<code>int [[strcoll]](const char *, const char *);</code>
|Confronta due stringhe utilizzando l'[[ordine lessicografico]] stabilito dalla [[localizzazione (software)|localizzazione]] utilizzata
|compares two strings using the current [[locale]]'s [[collating order]]
|-
|<code>char *[[strcpy]](char *s1, const char *s2);</code>
|Copia la stringa ''s2'' nella stringa ''s1'', incluso il carattere di terminazione ''\0''.
|copies a string from one ___location to another
|-
|<code>'''char *[[strncpy]](char *s1, const char *s2, size_t n);'''</code>
|Copia al massimo ''n'' caratteri della stringa ''s2'' in ''s1''.
|copies up to n bytes of a string from one ___location to another
|-
|<code>char *[[strerror]](int n);</code>
|Restituisce un puntatore alla stringa che corrisponde all'errore ''n''.
|returns the string representation of [[errno]] (not thread-safe)
|-
|<code>size_t [[strlen]](const char *s);</code>
|Restituisce la lunghezza della stringa ''s''.
|finds the length of a [[C string]]
|-
|<code>size_t [[strspn]](const char *s, const char *accept);</code>
|Restituisce la lunghezza della prima istanza della stringa ''s'' di lunghezza massima composta esattamente dai caratteri definiti della stringa ''accept''
|determines the length of the maximal initial substring of s consisting entirely of characters in accept
|-
|<code>size_t [[strcspn]](const char *s, const char *reject);</code>
|Restituisce la lunghezza della porzione iniziale della stringa ''s'' di lunghezza massima composta esattamente da caratteri diversi da quelli della stringa ''reject''
|determines the length of the maximal initial substring of s consisting entirely of characters not in reject
|-
|<code>char *[[strpbrk]](const char *s, const char *accept);</code>
|Restituisce la prima occorrenza di un carattere presente nella stringa ''s'' che sia uguale ad un qualsiasi carattere presente nella stringa ''accept''
|finds the first occurrence of any character in accept in s
|-
|<code>char *[[strstr]](const char *haystack, const char *needle);</code>
|Trova la prima occorrenza della stringa ''needle'' all'interno della stringa ''haystack''
|finds the first occurrence of [[Needle in a haystack|needle in haystack]]
|-
|<code>char *[[strtok]](char *s, const char *delimiters);</code>
|Spezza la stringa ''s'' in una serie di stringhe chiamate [token] in corrispondenza dei carattere delimitatore ''delimiters''
|parses a string into a sequence of tokens; non-thread safe
|-
|<code>size_t [[strxfrm]](char *dest, const char *src, size_t n);</code>
|Trasforma la stringa puntata da ''src'' secondo la [[localizzazione (software)|localizzazione]] in uso e copia i primi n caratteri di ''src'' nella stringa ''dest''
|transforms src into a collating form, such that the numerical sort order of the transformed string is equivalent to the collating order of src.
|}
 
===ExtensionsEstensioni toper ISO C===
{| class="wikitable"
|-
! NameNome !! NotesDescrizione !! SpecificationSpecifica
|-
|<code>char *[[strdup]](const char *);</code>
|alloca e duplica una stringa nella memoria
|allocates and duplicates a string into memory
|[[POSIX]]; originallyoriginariamente auna BSDestensione extensiondi [[BSD]]
|-
|<code>errno_t [[strcpy_s]](char *restrict s1, rsize_t s1max, const char *restrict s2);</code>
|bounds-checkedvariante variant ofdi <code>[[strcpy]]</code> che include dei controlli sulla lunghezza delle stringhe
|ISO/IEC WDTR 24731
|-
|<code>void *[[mempcpy]](void *dest, const void *src, size_t n);</code>
|variantvariante ofdi <code>memcpy</code> returningche aritorna pointerun topuntatore theal byte followingsuccessivo theall'ultimo lastbyte written bytescritto
|[[GNU]]
|-
|<code>void *[[memccpy]](void *dest, const void *src, int c, size_t n);</code>
|copia fino ad n byte fra due aree di memoria non sovrapposte, fermandosi quando viene trovato il byte c
);</code>
|copies up to n bytes between two memory areas, which must not overlap, stopping when the byte c is found
|UNIX 98?
|-
|<code>int *[[strerror_r]](int, char *, size_t);</code>
|returnsrestituisce theuna stringrappresentazione representationin stringa di un numero di errore (si ofveda [[errno]]) (thread-safe; somealcune differencesdifferenze insemantiche semanticsfra betweenla specifica [[GNU]] ande [[XSI]]/[[POSIX]])
|[[GNU]], [[POSIX]]
|-
|<code>size_t [[strlcpy]](char *dest, const char *src, size_t n);</code>
|bounds-checkedvariante variant ofdi <code>[[strcpy]]</code> che comprende controlli sulla lunghezza della stringa
|originallyoriginariamente [[OpenBSD]], nowora alsoanche [[FreeBSD]], [[Solaris Operating(sistema Systemoperativo)|Solaris]], [[Mac OS XmacOS|OS X]]
|-
|<code>char *[[strtok_r]](char *, const char *, char **);</code>
|versione thread-safe version ofdi strtok
|POSIX
|-
|<code>char *[[strsignal]](int sig);</code>
|analogamente a <code>strerror</code>, ritorna una rappresentazione in stringa del [[Segnale (informatica)|segnale]] <code>sig</code> (non thread safe)
|varie distribuzioni BSD, [[Solaris (sistema operativo)|Solaris]], [[Linux]]
|}
 
==ExternalAltri linksprogetti==
{{interprogetto|b=C/Appendice/Librerie standard}}
*{{man|3|string||string operations}}
 
-->
==Collegamenti esterni==
* {{cita web|https://linux.die.net/man/3/string|Operazioni su stringhe|lingua=en}}
 
{{Portale|Informatica}}
 
[[Categoria:Libreria standard del C]]
 
[[en:C string handling]]
{{Informatica}}