Ad
  • Default User Avatar

    your string is never nul-terminated because the line-ending logic has precedence over the nul-terminating logic in your if/else

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    it is now explained in the initial code

  • Custom User Avatar

    OP solved it, closing

  • Custom User Avatar

    start_address_of_string+strlen(string)-1 will give you the address of the last character.From there all you need do is dereference that pointer and compare with the ending part

  • Custom User Avatar

    Don't forget spoiler flag. Your code is basically:

    for (...) {
      if (...) return true;
      else return false;
    }
    

    This code means that it will only check 1 character and return instantly. At least one of these returns should be outside loops.

  • Default User Avatar
  • Custom User Avatar

    Looks like the size of the returned array.

  • Custom User Avatar

    You'll get a compiler warning when comparing the "int i" to "size_t arr_size".

    Default int is signed, while size_t is unsigned. In practice it won't matter until the arrays get very large (not tried in this kata)

  • Default User Avatar

    Unsigned Integer means that they have only positive values starting from 0.They donot have any negative values in their range.
    In signed integers they have range of [-2147483648 to 2147483647] where as unsigned integer has range of [0 to 4294967295].

  • Custom User Avatar

    this is a data type which can store natural numbers from 0 to 2n - 1 where n is the number of bits (usually 32)

  • Custom User Avatar

    It depends what you want to represent with values of given type. size_t is meant to be used for sizes of objects and indices into arrays. float is not suitable for that, because, for example, you cannot have an object of size 3.5. Its range can also be too small. int can have smaller range than size_t on some platforms, so it's not guaranteed to work well for sizes and indices, especially for very large objects and arrays.

  • Custom User Avatar
    • size_t is a type suitable for storing sizes of objects and often used for indexing.
    • stddef.h is required as one of header files which supplies size_t. size_t is defined also in other header files (https://en.cppreference.com/w/c/types/size_t), so including any of them would be ok.
    • stdbool.h is required as a header file which provides bool.
    • solution template does not use stdio.h, because, in its initial form, it does not use anything declared in this file. If your solution uses anything declared in stdio.h, you can include it.
  • Custom User Avatar

    You created a new array instead of swapping the values of the original array. In this case, args[0] and args[1] still have the same values.

  • Custom User Avatar

    Try to come up with one. You can also forfeit and unlock solutions, if you can't solve it.