First, you need to know that C manage nothing and forgive nothing, you are responsible of everything.
Quote:The program works find till the character length 170 and above. when I define the character below 170 it is showing segmentation fault
This is typical of array or buffer overrun, which using (read or write) beyond the end of array or buffer. It is not complicated to understand that 170 is the size of your buffer.
This line says:
fscanf(fptr1, "%[^\0]", str);
read the file in 1 go, no matter the size of file, no need to wonder why you get a segmentation fault.
Devil lays in details, so understanding that scanf will read data from a file is not complicated, but you need to study documentation to understand how to tell it to limit the size of the read. Or check the size of file before reading it.
scanf - C++ Reference