By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,203 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,203 IT Pros & Developers. It's quick & easy.

Error while reading text file using VisualStudio. (duplicate lines)

P: 8
I'm writing a parser, and im totally confused. Its apparently correct, but something is happening:

I do a fread command to a char array of the entire file (it isn't big), this is the file:

Expand|Select|Wrap|Line Numbers
  1. sphere
  2. {
  3.     center <-3,0,0>
  4.       radius 2
  5. }
  6. light
  7. {
  8.     direction <1, 1, 1>
  9.     color rgb(1,1,1)
  10. }
  11. camera
  12. {
  13.     parallel
  14.     position <1,0,0>
  15.     to <0,0,0>
  16.     up <0,1,0>
  17. }
  18. settings
  19. {
  20.      image_width 800
  21.      image_height 600
  22.      min_weight 1
  23.      max_recursion_level 1
  24. }
  25.  
but the buffer on the debug mode shows this:

Expand|Select|Wrap|Line Numbers
  1. sphere
  2. {
  3.     center <-3,0,0>
  4.       radius 2
  5. }
  6. light
  7. {
  8.     direction <1, 1, 1>
  9.     color rgb(1,1,1)
  10. }
  11. camera
  12. {
  13.     parallel
  14.     position <1,0,0>
  15.     to <0,0,0>
  16.     up <0,1,0>
  17. }
  18. settings
  19. {
  20.      image_width 800
  21.      image_height 600
  22.      min_weight 1
  23.      max_recursion_level 1
  24. }
  25. max_recursion_level 1
  26. }
  27.  
it is repeating the two last lines, and the parser fails because it's waiting for an EOF or other simbol..

probably it isn't on the fread sentence, but here it is:

Expand|Select|Wrap|Line Numbers
  1. fread(bufferdata, 1, 100000, fileIn);
  2.     buffer = bufferdata;
  3.  
bufferdata size is 10.000

What could be happening?


Thanks.
Dec 8 '09 #1
Share this Question
Share on Google+
1 Reply


P: 8
Nevermind, after almost 9 searches on google i found the answer..

fread won't append /0 to the end of the buffer it read, so i put it manually there, using the fread return value and it's working fine.


edit:
if any mod want to delete this one, you can do it. Thanks.
Dec 8 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.