/*
 * customLib.c
 *
 *  Created on: 21. 4. 2022
 *      Author: filip
 */

#include "customLib.h"

static FILE *wFile;

uint8_t overtyping(int32_t Number){
	return((uint8_t)Number);
}

int32_t overtypingBack(uint8_t Num){
	uint8_t ret;
	if (Num <= (unsigned int)INT_MAX)
	  ret = (uint8_t)Num; /*(1)*/
	else if (Num >= (unsigned int)INT_MIN)
	  ret = -(uint8_t)~Num - 1; /*(2)*/
	else
	  ret = INT_MIN; /*(3)*/

	return(ret);
}

void openFile(){
    wFile = fopen("Data.txt", "w");

    if (wFile == NULL)
      {
        printf("Error! Could not open file\n");
      }
}

void closeFile(){
	int temp = fclose(wFile);
	if(temp != 0){
		printf("Error! Could not close file\n");
	}
}

void writeToFile(const char* str){
	fprintf(wFile, "%s", str);
}
