your solution works fine. Many thanks.
I have another issue on the same script.
It happened that some montecarlo simulations do not converge and the script does not proced because of error in the fprintf data type.
when this happens it writes in the log file ERROR
To prevent the script from stopping, I am doing this way (i found it the easiest way):
while((check !="ERROR") || (check != "EOF")
fscanf(file_port "%s" check)
if(check == "ERROR")
but when i put the (check != "EOF") statement in the while loop it goes in infinte loop (because in the first montecarlo simulation i run, there is no error).
i think the log file i am pointing to is not closed or i am putting the wrong string for detecting the end of the file.
Thanks a lot again