English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Libreria standard C - <string.h>
Funzione della libreria C char *strtok(char *str, const char *delim) Dividi la stringa str Per un insieme di stringhe,delim Per il separatore.
Di seguito è riportata la dichiarazione della funzione strtok().
char *strtok(char *str, const char *delim)
La funzione restituisce la prima sottostringa divisa, se non ci sono stringhe da recuperare, restituisce un puntatore nullo.
Il seguente esempio dimostra l'uso della funzione strtok().
#include <string.h> #include <stdio.h> int main () { char str[80] = "This is - it.oldtoolbag.com - website"; const char s[2] = "-"; char *token; /* Ottieni la prima sottostringa */ token = strtok(str, s); /* Continua a ottenere altre sottostringhe */ while( token != NULL ) { printf( "%s\n", token ); token = strtok(NULL, s); } return(0); }
Compiliamo ed eseguiamo il programma sopra, il che produrrà i seguenti risultati:
Questo è it.oldtoolbag.com sito web