Ad
  • Default User Avatar

    @iggzy Yes the expected is 1, and this is the actual value I gave, but the test case is telling me that the expected is equal to 0. That's why I think something's wrong.

  • Default User Avatar

    "Actual" -> 'a' occurs twice(A and a) since lower/upper should be ignored so expected IS 1

  • Default User Avatar

    Are you sure you are replying to the correct comment?

  • Default User Avatar

    Thanks for answer!
    It was my mistake: empty input srting was reason of problem with memory.

  • Custom User Avatar

    OPTION 1

    You are probably malloc'ing the exact len of the string.
    For e.g.

       char *c = malloc(strlen(incoming)); 
    

    Instead try

       char *c = malloc(strlen(incoming) + 1); // you need an extra byte for the null character
    

    OPTION 2

    Make sure you are not free'ing memory prematurely and then writing to the memory that was allocated
    earlier. This can also cause SIGSEG to be raised.

    Alternatively, think of an approach which eliminates the need to do either malloc'ing or free'ing.
    This exercise is all about string examination, which doesn't require you to make copy of anything.
    Just count the number of distinct characters that occur more than once.

    One approach (in pseudo code) would be:

    duplicates <- 0
    for char in alphabets: 
       if count of occurrences of char in test_string > 1: 
          duplicates <- duplicates + 1 
    
    return duplicates
    
  • Default User Avatar

    C, use malloc() and free() for memory.

  • Custom User Avatar

    Which language are you try to solve this kata in?

  • Default User Avatar

    your first order of business is to study your code for which line has the bug causing the Invalid memory access error message. it's likely that you're trying to assign a value to an unavailable memory location, such as beyond the bounds of memory allocated for a static array...

    EDIT: okay, those look like random tests. they are going to be different all the time.

  • Default User Avatar

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

  • Default User Avatar
    #include <stdio.h>
    printf("text = %s\n", text);
    
  • Default User Avatar

    Hi everyone!
    Solution passed all sample tests, works fine in IDE, but when I try attempt I get next error in one of tests:
    Test Crashed
    Caught unexpected signal: SIGSEGV (11). Invalid memory access.
    How can I get string, which crashed test?
    Thanks!

  • Default User Avatar

    "aabBcde" -> 2 # 'a' occurs twice and 'b' twice (b and B)

  • Default User Avatar

    A
    c
    t
    u
    a
    l
    Expected: equal to 0
    Actual: 1

    What's wrong?