Few things, code-tagged and commented.
programtoedit = read()
fileopen = fs.open(programtoedit, "r") --I notice you never check whether or not the file exists. Might do that or it will simply run without any of it, leaving you wondering what went wrong
what-it-says = fileopen.readAll()
fileopen.close()
print(what-it-says)
linetoedit = read() -- You will need a tonumber around this read.
whattowrite = read()
file-editer = fs.open(programtoedit, "a") -- Append will only tack on to the end. Open it in Write.
file-editer.writeLine(whattowrite, linetoedit) --This is not how writeLine works. writeLine just puts in \n at the end for you instead of you needing to do so.
file-editer.close()
The easier method of doing this is to delete the file after you have it, modify the line, replace the line in the table, then when finished, write the whole thing back to a similar place.So, something akin to this:
progEdit = io.read()
editProg = {}
if fs.Exists(progEdit) then
fileIn = fs.Open(progEdit, r)[/font][/color]
editProg = fileIn[/font][/color].readAll()
fileIn.close()
else
print("No such file")
return
end
--I'm leaving out the print here because that could be a problem for programs longer than 18 lines.
while true do
term.clear()
term.setCursorPos(1,1)
term.write("Line to edit: ")
lineEd = tonumber(io.read())
print(" ")
print(editProg[lineEd])
print(" ")
break
end --This while loop for asking the user if the line is correct.
print("What is the new line to read?")
writeWhat = io.read()
editProg[lineEd] = writeWhat
fileOut = fs.open(progEdit, w) --Now, I'm not sure how to make it start at line 1, but I think just overlaying the table on top of it works. Mystic or somebody will probably correct me.
for x=1, #editProg do
fileOut.writeLine(editProg[x])
end
fileOut.close()
Now, this is only simple code. Eventually, this would have to have a way to modify line in real time, instead of a response based program. But, that is something I don't think anyone can do on the fly. Also, for future reference, the forum has what they call code tags. It's the little button with "<" and ">" on it. Makes life easier on everyone involved.