joshhartigan / iu-coreutils

alternative, simpler coreutils - not a GNU fork/clone
BSD 2-Clause "Simplified" License
18 stars 2 forks source link

lnum.c doesnt handle lines longer than 1024 chars #4

Open su8 opened 6 years ago

su8 commented 6 years ago

Also no format specifier is used to tell to the program to scan until the newline character is met.

edit: I've mistaken f/scanf with fgets

su8 commented 6 years ago

The solution which I would like to propose is to read the file content at once with malloc, and split the string into tokens. This way no matter how long a single line could be, it will be numbered properly. I will use this strategy to contribute around 10 programs later on next week.

su8 commented 6 years ago

https://github.com/joshhartigan/iu-coreutils/blob/46bfa8d008c000fe6d0a1c78d3d6e7143700f942/lnum.c#L17

Shadowing the function read() isn't pretty.