Here you have it, just try to match the parenthesis
(defun c:FT ( / fo txt pt1 pt2)
(setq folder "c:\\fatih\\")
(setq file (strcat folder (getvar "dwgname") ".csv"))
(setq fo (open (setq fname file) "a"))
(write-line "Size,Length" fo)
(while (setq tent (entsel "Pick text"))
(setq txt (cdr (assoc 1 (entget (car tent)))))
(setq sumdist 0)
(setq P1 (getpoint "\nSelect first point: "))
(while (setq P2 (getpoint P1 "\nSelect next point, or press Enter to close: "))
(prompt (strcat "\nLatest distance = " (rtos (distance P1 P2)) ",\nCumulative distance = "
(rtos (setq sumdist (+ sumdist (distance P1 P2))))
); end strcat
); end prompt
(setq P1 P2)
); end while
(prompt (strcat "\nTotal sum of distances = " (rtos sumdist)))
(princ)
(write-line (strcat txt "," (rtos sumdist 2 0)) fo)
(princ)
); end while
(close fo)
); end defun
And always a pretty-print is very helpful