r/cprogramming • u/DogWallop • May 18 '26
Getting Formatting Errors Loading .C Files in Turbo C for DOS
I am having a problem with loading .c files in ye olde Borland Turbo C for DOS 2.01. .C files will display properly if I load them in any other editor on earth, under any other operating system, but Turbo C seems to ignore line feeds(?) when loading that same file into it's IDE editor. It will throw out an error about the line being too long, etc.
Sincerely,
Getting a Bit Annoyed in Bermuda
Edit: Thanks all for your input. I found that if I loaded the file into an editor that would format it properly and then resaved it was fixed
Cheers!
6
u/flatfinger May 18 '26
In the MS-DOS era, non-Unix systems that used a bare carriage return as a newline were more common than non-Unix systems that treated a linefeed in such fashion. Consequently, many programs including Turbo C would accept text files where newlines were indicated as bare carriage returns, but choke on files where they were indicated with bare linefeeds. It should be simple to write a program that will open a file in binary mode for reading and another for writing, reach each byte of the former, and implement a simple state machine that would ignore any carriage return that followed a linefeed that was not ignored, or any line feed that followed a carriage return that was not ignored, output a CR+LF pair for any linefeed or carriage return that was not ignored, gobble any byte 0x1A and ignore everything after it, and otherwise pass input data through unmodified. Such a program would convert all of the line endings in a file to MS-DOS format.
1
u/mlugo02 May 18 '26
Loading as in opening a file ?
3
u/EpochVanquisher May 18 '26
Do you use proper CRLF for the end of the line? Or just LF?
You can use programs like unix2dos / dos2unix to convert line endings.
1
u/Plane_Dust2555 May 19 '26
With vim, open the file and:
1
u/Sb77euorg May 23 '26 edited May 23 '26
Why are you using turbo c for DOS ???? Are you trying to to learn c??? Checkāpelles cā is a free windows idea + compiler for c (use windows console project)