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.


  1. /**
  2. Sviluppare una function C che, data come parametro di input una stringa che
  3. rappresenta un testo in italiano, determina e restituisce come parametri di output la
  4. parola di lunghezza minima contenuta nel testo e la posizione di inizio della parola
  5. nella stringa. Nel testo le parole sono separate da un unico spazio.
  6. **/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. int a(char* str ,char* max_word);
  12. int main ()
  13. {
  14.     char s[]="a ullare laboris nisare utt aliquid ex ea comaamodi consequat a";
  15.     char* t;
  16.     printf("%d %s",a(&,&t), &t);
  17.  
  18. }
  19.  
  20. int a(char* str ,char* max_word)
  21. {
  22.     char *temp,*tmp;
  23.     int len_max;
  24.     len_max=0;
  25.     for (temp = strtok(str," "); temp != NULL; temp = strtok(NULL, " "))
  26.         {
  27.         if(strlen(temp)>len_max)
  28.             {
  29.                 len_max=strlen(temp);
  30.                 strcpy(max_word,temp);
  31.                 tmp=temp;
  32.             }
  33.         }
  34.         // LA POSIZIONE DI INIZIO DELLA PAROLA DI LUNGHEZZA MINIMA E' DATA DALL'INDIRIZZO
  35.         // DELLA PAROLA - INDIRIZZO DELLA FRASE
  36.         // ESEMPIO, SE LA PAROLA SI TROVA NELLA LOCAZIONE 8100, E IL PUNTATORE DI INIZIO DELL'INTERA FRASE PUNTA A 8000
  37.         // LA POSIZIONE DELLA PAROLA IN ESAME SARA' A 100.
  38.     return ((int)tmp - (int)str);
  39. }


Learn More :