![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| reading a file inside awk and processing line by line | Anteus | Shell Programming and Scripting | 6 | 06-22-2009 11:05 AM |
| KSH: Reading a file line by line into multiple arrays | sniper57 | Shell Programming and Scripting | 2 | 06-09-2009 04:47 AM |
| Reading a file line by line and processing for each line | sagarparadkar | Shell Programming and Scripting | 6 | 03-02-2009 11:59 AM |
| Split a line on positions before reading complete line | vijaykrc | Shell Programming and Scripting | 1 | 02-18-2009 07:23 PM |
| URGENT HELP NEEDED ON -File size reading | jambesh | Shell Programming and Scripting | 1 | 07-06-2008 09:31 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
For line-based I/O, you want a maximum. Otherwise, when fed an endless line, your program will allocate endless amounts of memory. Make it a large maximum if you want, but give it some sort of maximum. Also note that while you can make your limit as large as you feasibly want, there are plenty of UNIX commandline tools, like standard sed and grep, that won't handle lines larger than 2048 bytes. Even things like uuencoding that translate raw binary into ASCII have measures to limit their line length because it's always in your best interest to keep line lengths reasonable.
Furthermore, reading more than one character at a time won't let you "unget" the extra data read beyond the end of line. You can unget one and only one character. So you have to read one-at-a-time if you want to keep all your data. Also, your algorithm overcomplex, there's no need for a linked list or other data structure. You can resize already-allocated memory with realloc(). It's location may change, but already-defined data will stay defined, while the new area on the end will be undefined until you overwrite it. I'd just use fgets() with a limit of a few kilobytes. If you really wanted to be sure, make the limit configurable with a commandline switch, just in case. Last edited by Corona688; 4 Weeks Ago at 02:20 PM.. |
|
|||||
|
corona
thanks for the insight. i didn't knew about other programs having a line limit, and neither tough of the "endless" line problem about realloc, never crossed my mind, and it does surely sounds safer than keeping a list tight :P thanks for the info |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|