Sometimes, this code works just fine, but sometimes the process ends and returns 3 which means that there is an error (3 is the return value that I usually get when I try to use NULL where I shouldn't like for example

myPointer->example

where

myPointer

is NULL). After some tests, I found out that the line that was causing the problem is

free(temp);

. I tried to replace it with

if(temp != NULL){free(temp);}

but it didn't change anything. I tried to declare

temp

with

char temp[1000]

instead of

malloc

and take away the

free(temp);

line but it still does the same thing. If I take away the

free(temp);

line and still use

malloc

the problem is solved but instead there is a huge memory leak, so I can't do that. If there is an error or not depends on what is in the

myString

string, which means that if there is a certain value in there, there always is an error, and if there is another certain value, there never is an error, but I can't manage to find out what type of values work and which ones don't, it seems to be random.