Ad
  • Default User Avatar

    This is not an issue, this is a question ;-)

    Your code is incorrect and you have to debug it
    I see several mistakes :

    • you are incrementing the word count at each space that you encounter, but words can be separated by more than one space : "a b"
    • you are allocating a fixed size buffer (malloc(256)) without being sure it will be enough in the worst case scenario
    • there is a mismatch between the type and the size you allocate for it there:
      char (*words)[len] = malloc (sizeof(char[word_count][len]) );
      
      words is a pointer to a char array of length len
      you allocate the size of an array of length word count of array of length len of char
      also note that you forgot to add +1 for the nul terminator

    Your approach is too complicated. You dont need to allocate a 2D array to store every word. You can solve this in only 1 pass of the input string, keeping track of the current longest word as you go

  • Default User Avatar

    same here.

    "
    The expression (as strings) (res) == ("taxi") is false: actual=taxi expected=taxi.
    "

  • Custom User Avatar
  • Custom User Avatar

    Don't give free hints and let people solve the kata by themselves, that's part of the learning process, just like it has been for you. I marked your message as a spoiler.