<commit_before>#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

#include "anagram.h"

char *lowercase(char *p)
{
   int len = strlen(p) + 1;
   char *lower = (char *)malloc(len);
   memcpy(lower, p, len);
   p = lower;
   while (*p) {
      *p = tolower(*p);
      p++;
   }

   return lower;
}

int compare(const void *a, const void *b)
{
   return *(const char *)a - *(const char *)b;
}

struct Vector anagrams_for(char *in, struct Vector vin)
{
   struct Vector vout = {
      malloc(MAX_STR_LEN * sizeof(char *)),
      0
   };
   char (*vout_vecp)[MAX_STR_LEN] = vout.vec;

   char *lower = lowercase(in);
   char *sorted = malloc(strlen(in));
   memcpy(sorted, lower, strlen(in));
   qsort(sorted, strlen(sorted), 1, compare);

   char (*vecp)[MAX_STR_LEN] = vin.vec;
   int x;
   for (x = 0; x < vin.size; x++) {
      char *input_lower = lowercase((char *)vecp);
      if (strcmp(input_lower, lower) != 0) {
         char *input_sorted = input_lower;
         qsort(input_sorted, strlen(input_sorted), 1, compare);
         if (strcmp(sorted, input_sorted) == 0) {
            strcpy(*vout_vecp, *vecp);
            vout_vecp++;
            vout.size++;<commit_msg>anagram: fixing strlen error (#76)<commit_after>#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

#include "anagram.h"

char *lowercase(char *p)
{
   int len = strlen(p) + 1;
   char *lower = (char *)malloc(len);
   memcpy(lower, p, len);
   p = lower;
   while (*p) {
      *p = tolower(*p);
      p++;
   }

   return lower;
}

int compare(const void *a, const void *b)
{
   return *(const char *)a - *(const char *)b;
}

struct Vector anagrams_for(char *in, struct Vector vin)
{
   struct Vector vout = {
      malloc(MAX_STR_LEN * sizeof(char *)),
      0
   };
   char (*vout_vecp)[MAX_STR_LEN] = vout.vec;

   char *lower = lowercase(in);
   char *sorted = malloc(strlen(in) + 1);
   memcpy(sorted, lower, strlen(in) + 1);
   qsort(sorted, strlen(sorted), 1, compare);

   char (*vecp)[MAX_STR_LEN] = vin.vec;
   int x;
   for (x = 0; x < vin.size; x++) {
      char *input_lower = lowercase((char *)vecp);
      if (strcmp(input_lower, lower) != 0) {
         char *input_sorted = input_lower;
         qsort(input_sorted, strlen(input_sorted), 1, compare);
         if (strcmp(sorted, input_sorted) == 0) {
            strcpy(*vout_vecp, *vecp);
            vout_vecp++;
            vout.size++;
{'fraction_non_alphanumeric': 0.16591375770020533, 'fraction_numerical': 0.007392197125256674, 'mean_word_length': 2.8728139904610495, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '948020', 'n_tokens_mistral': 941, 'n_tokens_neox': 913, 'n_words': 225}