Ad
  • Default User Avatar

    The problem may be that when you allocate your char array with c = (char *)malloc(sizeof(char) * (i + 1));, you are not setting the last element c[i] to 0 (or '\0'). Remember that malloc does not initialize any memory, it only allocates it (but calloc will initialize to 0). This can cause a problem with strcmp since it compares the strings up until it reaches 0 on one or both of them.