Ant parse file line by line




















Viewed 39k times. Can you give more context? What are you trying to do? See: ant. Add a comment. Active Oldest Votes. Lesmana Lesmana I cant install ant-contrib in my application. Could you please tell me how to read only the first line of a file, without using for — rashok.

I cannot find it in the ant documentation. Is it used to split by line? It's a resource collection, see ant. Try This it should be work Alexis Pigeon 7, 11 11 gold badges 38 38 silver badges 44 44 bronze badges.

Aniket Patil Aniket Patil 87 1 1 silver badge 3 3 bronze badges. After checking, the man page says that free ptr ; free ptr ; is undefined, and that free NULL does nothing. Still, this website is all about teaching or helping with the best solution possible, and freeing every allocated memory that isn't used anymore is actually the good practice to have. Show 15 more comments. Rob Rob 5, 4 4 gold badges 40 40 silver badges 48 48 bronze badges.

For me this results in overwriting each line with the next. See this question based on the above answer. If you're ok with lines being limited to a certain length, this is the best answer. Otherwise using getline is a good alternative. I removed the un-necessary cast, added a variable for the buffer length and changed fp to filePointer for more clarity. It should be const int bufferLength if pedantic: — baz. Show 1 more comment. Iron: I've added something to my answer, but I'm not sure what your difficulty is so it may be off the mark.

Iron: the answer is that you don't free it. You document in the API documentation the fact that the returned buffer is malloc'd ansd needs to be freed by the caller. Then people who use your readLine function will hopefully! PearsonArtPhoto 37k 17 17 gold badges silver badges bronze badges.

RevoLab RevoLab 1 1 gold badge 5 5 silver badges 8 8 bronze badges. Null bytes will make all the characters in the rest of the line vanish. Do not tell me null bytes cannot happen! And by the way, you do not solve the problem. The OP describes that the return value of his function disappears. I do not see you addressing this problem. Hartley I know this is an older comment, but I am adding this so that someone doesn't read his comment and try to free line in the loop.

The memory for line is only allocated once before the loop begins, so it should only be free once after the loop ends. If you try freeing line inside the loop, you will get unexpected results. Depending on how free treats the pointer. If it just deallocates memory and leaves the pointer pointing at the old location the code may work. If it assigns another value to the pointer then you will overwrite a different section of memory.

Do not do this. To get around you can: Create variable in caller function and pass its address to readLine Allocate memory for line using malloc - in this case line will be persistent Use global variable, although it is generally a bad practice. I found this piece of description in: linux. Raku Escape Raku Escape 3 3 silver badges 3 3 bronze badges. Also error messages should go to stderr i. This is important since the comparison with EOF will be handled correctly.

JeremyP JeremyP Also, you need to tell the function how long the buffer is that you are passing and think of a strategy for handling lines that are too long for the buffer you pass in. Here is my several hours Reading whole file line by line. Akhil V Suku 1 1 gold badge 10 10 silver badges 33 33 bronze badges.

Samir Samir 5, 4 4 gold badges 34 34 silver badges 38 38 bronze badges. Why are you using fgetc instead of fgets? Viewed k times. How can I do that line by line? Improve this question. Add a comment. Active Oldest Votes. Improve this answer. SeanC SeanC Remember Close FileNum at the end! NoChance, not if the file is just as expected, but programming styles were not what the question is about. Show 2 more comments. OpenTextFile filePath, ForReading, False Then with this txtStream object you have all sorts of tools which intellisense picks up unlike using the FreeFile method so there is less guesswork.

You can read a file like: Do While Not txtStream. AtEndOfStream txtStream. ReadLine Loop txtStream. Robino 3, 2 2 gold badges 28 28 silver badges 36 36 bronze badges. Brad Brad I think this also will accomplish what I wanted just fine — dancran. Actually, without dimensioning txtStream as a TextStream object, there will be no intellisense — ElRudi.



0コメント

  • 1000 / 1000