I suppose you have defined string type as:
typdef char * string;
In that case, change
string newtext = text;    /// Here, both point to same memory
to
string newtext = strdup(text);
solved Why are my strings changing unintentionally?
 
I suppose you have defined string type as:
typdef char * string;
In that case, change
string newtext = text;    /// Here, both point to same memory
to
string newtext = strdup(text);
solved Why are my strings changing unintentionally?