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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spiralfire
    New Member
    • Nov 2009
    • 8

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

    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:

    Code:
    sphere
    {
    	center <-3,0,0>
      	radius 2
    }
    light
    {
    	direction <1, 1, 1>
    	color rgb(1,1,1)
    }
    camera
    {
    	parallel
    	position <1,0,0>
    	to <0,0,0>
    	up <0,1,0>
    }
    settings
    {
         image_width 800
         image_height 600
         min_weight 1
         max_recursion_level 1
    }
    but the buffer on the debug mode shows this:

    Code:
    sphere
    {
    	center <-3,0,0>
      	radius 2
    }
    light
    {
    	direction <1, 1, 1>
    	color rgb(1,1,1)
    }
    camera
    {
    	parallel
    	position <1,0,0>
    	to <0,0,0>
    	up <0,1,0>
    }
    settings
    {
         image_width 800
         image_height 600
         min_weight 1
         max_recursion_level 1
    }
    max_recursion_level 1
    }
    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:

    Code:
    fread(bufferdata, 1, 100000, fileIn);
    	buffer = bufferdata;
    bufferdata size is 10.000

    What could be happening?


    Thanks.
  • spiralfire
    New Member
    • Nov 2009
    • 8

    #2
    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.

    Comment

    Working...