Reason for infinite loop is inner loop:
while(j!=0 && temp_string != NULL){ //Here
^ ^ never set to NULL
| never became 0 if "Delimiter2" not found
Suppose, if in temp_string value is not "Delimiter2"
then you never set to j
= 0 and also you don't set temp_string to NULL
You read in temp_string 100
char at once so "Delimiter2"
might be read from file with some other charters that is the reason strcmp() doesn't return 0 even on reading "Delimiter2"
.
Try to bug your code by printf you temp_string.
Also, you can use strstr()
function in place of strcmp()
to find "Delimiter2"
in your file. strstr()
return a valid address if "Delimiter2"
found any where in temp_string, other wise NULL.