<commit_before>//This is a preliminary version of this file for testing and learning purposes
//Author: <NAME>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

char* getMessage(char* filename){
  char* msg = NULL;
  int   msgLength, txtLength;
  FILE *fp = fopen( filename, "r");

  if(fp){
    //Find end of text file, find file size, and go back to beginning of file.
    fseek(fp, 0, SEEK_END);
    msgLength = ftell(fp);
    fseek(fp, SEEK_SET, 0);

    //Allocate memory for the string
    msg = ((char*) malloc(sizeof(char) * msgLength+1));

    //Read the entire file pointed to by fp in chunks of 2 byte to the string msg and store the read size in txtLength.
    txtLength = fread(msg, sizeof(char), msgLength, fp);
    msg[msgLength] = '\0';
    fclose(fp);
    //Error check
    if(msgLength != txtLength){
      //The read failed somehow. Abort mission.
      free(msg);
      msg = NULL;
      return "Error: Length of file not equal to length of read. That's probably my fault -Jonas";
      }

    return msg;
    }
  else{
    return "Error: File not found. Please contact the poor students who made this.";
    }
}

int main(){
  char* filename = "C:/Users/iacob/Desktop/msg.txt";
  printf("%s\n", filename);
  char* message = getMessage(filename);
  printf("%s\n", message);
  return 0;
}<commit_msg>Fix memory allocation, define maximum message length and filename, add explanatory comments to file<commit_after>/*
 *inputhandler.c will read a string from a text file, and format it so that the sign can use it.
 *Finally it will send the formatted data to a program responsible for the wireless transmission.
 *Author: <NAME>
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

#define MAXMSGLENGTH 500
#define FILENAME "C:/Users/iacob/Desktop/msg.txt"

/*
 * The getMessage function reads from the file specified and puts the content in msg.
 * The specified file should contain nothing but text. Returns a reference to the changed string.
*/
char* getMessage(char* filename, char* msg){
  int   msgLength;
  FILE *fp = fopen( filename, "r");

  if(fp){
    //Find end of text file, find file size, and go back to beginning of file.
    fseek(fp, 0, SEEK_END);
    msgLength = ftell(fp);
    fseek(fp, SEEK_SET, 0);

    //Read the entire file pointed to by fp in chunks of 2 byte to the string msg and store the read size in txtLength.
    fread(msg, sizeof(char), msgLength, fp);
    msg[msgLength] = '\0';
    fclose(fp);

    return msg;
    }
  else{
    return "Error: Message file failed to open. Please contact the poor students who made this.";
    }
}

/*
 *Runs the functions getMessage, format, and transmit,
 *as well as initializing and cleaning up the required variables.
*/
int main(){
  //Allocate memory for the message string, the same array will be overwritten for subsequent messages.
  char* message = ((char*) malloc(sizeof(char) * MAXMSGLENGTH+1));

  //Call getMessage to read the content of filename into the string message
  getMessage(FILENAME, message);
  printf("%s\n", message);

  //Free memory for the message string
  free(message);
  //Exit
  return 0;
}
{'fraction_non_alphanumeric': 0.1117054751415985, 'fraction_numerical': 0.004719949653870359, 'mean_word_length': 3.3848275862068964, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '736369', 'n_tokens_mistral': 1007, 'n_tokens_neox': 962, 'n_words': 404}