ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hi, i am trying to read in a file 1 line at a time and for some reason it stops printing out at about line 62,000.
i am doing this:
Code:
while(fgets(c0, 1085, fstream0) != NULL)
but after about 62,0000 lines it stops printing. no seg-fault, no core dump. it just stops printing to the terminal then returns me to the command line after a couple of minutes.
as a hack i am doing split -l 50000 on the input and calling my program 5 times.
is there some limitation on fgets that i am not understanding ?
There is no limit to fgets().
Does it end by EOF or an error?
Is the buffer really large enough? (Why the literal 1085?) You are not guaranteed a segfault just because memory is overwritten.
There is no limit to fgets().
Does it end by EOF or an error?
Is the buffer really large enough? (Why the literal 1085?) You are not guaranteed a segfault just because memory is overwritten.
i = 59510
12345678900-0004:FLD-1
12345678900-0004:FLD-29
i = 59511
abcdefghi00-0005:FLD-1
-:FLD-78
i = 59512
i = 59513
i = 59514
i = 59515
...
i = 168301
^ thx, i should call free() 2 times for each if then 3 more times if true.
not sure where to inject those free()'s since i didnt save those pointers (i figured the code would be more compact this way).
edit:
fyi: i tried this on a few fields (the ones that yielded the most hits):
tail test.out
i = 168297
aaaaaaaaa00-0002:FLD-64
i = 168298
bbbbbbbbb00-0001:FLD-64
i = 168299
ccccccccc00-0001:FLD-64
i = 168300
ddddddddd00-0001:FLD-64
ddddddddd00-0001:FLD-78
i = 168301
eeeeeeeee00-0001:FLD-64
You still have errors. It maybe work correctly now, but someday 'blow up'. Follow rupertwh notices from #5 post (points 1. and 3.). Also you made 'free()' outside of 'if()' - you possibly freed unallocated memory. Split your 'one-line' code to more lines, for example:
Essentially it is nothing bad with writing code in 'one-line' style, but it is more readable and easier to see errors in multiple lines. Just out of curiosity - are you perl programmer?
^ damn it, i didnt think strcmp had a strncmp counterpart. (the man pages on this aix server are broken).
i am done with this assignment for now so i will revisit this next release.
note to self: sed s/strndup/strncmp/g compare.c
no i dont do perl more of a bash/ c guy (but now i am understanding sed-awk a little bit too).
thx eselix, rupertwh: i give you 2-points.
i also didnt know you can byte-offset an array inside a printf. i'm glad i took this program, i'm making mistakes but learning alot.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.