Yes so i found a solution to the problem. It just needed a space before the %[^\n] in scanf.
scanf(" %[^\n]s", str);