set FileId1 [open D:/data.txt r]
set FileId2 [open D:/result.txt w]
gets $FileId1 str1
set len [llength $str1]
set i 0
while {![eof $FileId1]} {
gets $FileId1 str2
while {$i<$len} {
puts $FileId2 "[lindex $str1 $i] : [lindex $str2 $i]"
incr i 1
}
puts $FileId2 " "
}
close $FileId1
close $FileId2
原来是i赋值出了问题 ,谢谢dpdpdp指点
因为set i 0放在while循环外面,所以当外层while循环一次以后再循环第二次时由于i没有重新赋值,内层while循环无法执行,导致没有输出,所以只要把set i 0放到外层while循环里面就可以了
set FileId1 [open D:/data.txt r]
set FileId2 [open D:/result.txt w]
gets $FileId1 str1
set len [llength $str1]
while {![eof $FileId1]} {
set i 0
gets $FileId1 str2
while {$i<$len} {
puts $FileId2 "[lindex $str1 $i] : [lindex $str2 $i]"
incr i 1
}
puts $FileId2 " "
}
close $FileId1
close $FileId2