/**
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 posizione di inizio della parola
nella stringa. Nel testo le parole sono separate da un unico spazio.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int a(char* str ,char* max_word);
int main ()
{
char s[]="a ullare laboris nisare utt aliquid ex ea comaamodi consequat a";
char* t;
printf("%d %s",a(&s ,&t), &t);
}
int a(char* str ,char* max_word)
{
char *temp,*tmp;
int len_max;
len_max=0;
for (temp = strtok(str," "); temp != NULL; temp = strtok(NULL, " "))
{
if(strlen(temp)>len_max)
{
len_max=strlen(temp);
strcpy(max_word,temp);
tmp=temp;
}
}
// LA POSIZIONE DI INIZIO DELLA PAROLA DI LUNGHEZZA MINIMA E' DATA DALL'INDIRIZZO
// DELLA PAROLA - INDIRIZZO DELLA FRASE
// ESEMPIO, SE LA PAROLA SI TROVA NELLA LOCAZIONE 8100, E IL PUNTATORE DI INIZIO DELL'INTERA FRASE PUNTA A 8000
// LA POSIZIONE DELLA PAROLA IN ESAME SARA' A 100.
return ((int)tmp - (int)str);
}