为什么不能写入文本?
我写的程序意图是:读取文本数据,使的数据中的X ,Y,H,能够同时加一个给定的常数,同时保存为原来的文本数据格式,程序运行中只能将原第二行的数据,加常数后写入新的文件中。我想是不是循环的问题,但是还是没有解决,请帮忙!为什么没有高手相助呢?帮帮忙吧!
你不给个文件,让人无法调试,这样必须从头将程序看懂,太费劲,
meflying兄,我把文件及程序再上传!请帮助,多谢!
本帖最后由 作者 于 2003-5-23 22:13:47 编辑看看是不是这个意思
你每一行加的数值不一样吗?而且每一行都要另存一个文件吗?另外,保存文件用参数9。
看看下面的程序能否满足你的要求
1
(defun readtxt(str / lists )(setq lists (list (read str)))
(setq str (vl-string-left-trim (rtos (car lists)) str))
(setq str (vl-string-trim ", " str))
(setq lists (append lists (list (read str))))
(setq str (vl-string-left-trim (rtos (cadr lists)) str))
(setq str (vl-string-trim ", " str))
(setq lists (append lists (list (read str))))
(setq str (vl-string-left-trim (rtos (caddr lists)) str))
(setq str (vl-string-trim ", " str))
(setq lists (append lists (list (read str))))
)
2
(defun puttxt(f lists / n m i j str)(setq n (length lists))
(setq m (length (car lists)))
(setq i 0)
(while (< i n)
(setq j 1)
(setq str (strcat (rtos (car (nth i lists))) " ,"))
(while (< j m)
(setq str (strcat str "," (rtos (nth j (nth i lists))) " "))
(setq j (1+ j))
)
(write-line str f)
(setq i (1+ i)))
)
3
(defun c:sjjcs (/ x y h xg yg hg x_xg y_yg h_hg lists list1 ft fm fn)(setq file (findfile "*.txt"))
(if (not file)
(setq file (getfiled "\n请输入原数据文件" "e:\\" "txt;dat;*" 8))
)
(setq fn (open file "r"))
(read-line fn)
(setq ft (read-line fn))
(setq lists nil)
4(1、2、3、4、5按顺序粘贴到一个文件中,再存为*.lsp文件)
(setq xg (getreal "\n北方向加固定常数(X + <10>) :"))(if (null xg) (setq xg 10))
(TERPRI)
(setq yg (getreal "\n东方向加固定常数(Y + <20>) :"))
(if (null yg) (setq yg 20))
(TERPRI)
(setq hg (getreal "\n高程加固定常数(H + <30>) :"))
(if (null hg) (setq hg 30))
(while ft
(setq list1 (readtxt ft))
(setq x (nth 1 list1))
(setq y (nth 2 list1))
(setq h (nth 3 list1))
5
(setq x_xg (+ x xg))(setq y_yg (+ y yg))
(setq h_hg (+ h hg))
(setq list1 (list (car list1) x_xg y_yg h_hg))
(setq lists (append lists (list list1)))
(setq ft (read-line fn)))
(close fn)
(setq fm (getfiled "请指定保存新数据的路径及文件名""e:\\DATA1.TXT""txt;dat;*"9))
(setq n_file (open fm "w"))
(puttxt n_file lists)
(close n_file)
(princ)
)
页:
[1]
2