title: Minimum Length Word in a string (C++)
body: <p>Given a string S (that can contain multiple words), you need to find the word which has minimum length.
  Note : If multiple words are of same length, then answer will be first minimum length word in the string.
  Words are separated by single space only.</p>
  
  <pre><code>Input Format :
  String S
  Output Format :
  Minimum length word
  Constraints :
  1 &lt;= Length of String S &lt;= 10^5
  Sample Input 1 :
  this is test string
  Sample Output 1 :
  is
  Sample Input 2 :
  abc de ghihjk a uvw h j
  Sample Output 2 :
  a
  </code></pre>
  
  <p>Please check what is wrong. There is nothing coming in the output.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>   /* input - Input String
  *  output - Save the result in the output array (passed as argument). You don’t have to 
  *  print or return the result
  */
  
  int length(char input[], int si, int ei){
      int len = 0;
      for(int i = si; i &lt;= ei; i++){
          len++;
      }
      return len;
  
  }
  
  char getString(char input[], int index){
      return input[index];
  }
  
  void minLengthWord(char input[], char output[]){
      int prev = -1;
      int i = 0;
      int minLength = 0, len = 0;
      int si, ei;
      for(; input[i] != '\0'; i++){
          if(input[i] == ' '){
              int len = length(input, prev + 1, i - 1);
              if(len &gt; minLength){
                  minLength = len;
                  si = prev + 1;
                  ei = i - 1;
              }
              prev = i;
          }
  
      }
      length(input, prev + 1, i - 1);
      if(len &gt; minLength){
                  minLength = len;
                  si = prev + 1;
                  ei = i - 1;
              }
      for(int i = 0; i &lt; minLength; i++){
           output[i] = getString(input, si + i);
      }
  
  
      // Write your code here 
  
  }
  </code></pre>