Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Sviluppare una function C che, data come parametro di input una stringa che
- rappresenta un testo in italiano, determina e restituisce come parametri di output la
- parola di lunghezza minima contenuta nel testo e la sua lunghezza. Nel testo le
- parole sono separate da un unico spazio.
- **/
- #include <string.h>
- #include <stdio.h>
- char *func(char *text, int *lenght) {
- char *word, *ret, *buff = strdup( text );
- int len, oldlen;
- oldlen = strlen(buff);
- while((word = strtok(buff, " "))) {
- buff = NULL; // See strtok man page
- len = strlen(word);
- if(len < oldlen) {
- oldlen = len;
- ret = word;
- *lenght = len;
- }
- }
- return ret;
- }
- int main(void) {
- char *testo = "ullamcoare laboris nisare utt aliquid ex ea comaamodi consequat";
- int len;
- char *ret = func(testo, &len);
- printf("Parola: %s\nLunga: %d\n",ret, len);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment