sscanf for a string from a file

Discussion in 'C' started by biaspoint, Sep 7, 2010.

  1. biaspoint

    biaspoint New Member

    Joined:
    Sep 7, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I am reading in a csv that contains 13 columns, the first column is the name of an image, for example "picture.tiff" the next 12 are numerical parameters using a decimal, for example "23.45". I had no problem parsing it when I made everything a number (instead of picture.tiff, I used 0001 for image names and later appended .tiff to it to open)... So I was thinking I would be more efficient and save the complete image name in the csv. However now I can parse the string, but not the numerical parameters following... as usual I think I must be going crazy and need to lay off the coffee. FYI I am saving everything in to a struct.

    Code:
    char line [ 180 ];
    fp= fopen(csvfilename,"r");
    fgets(line, sizeof line, fp); //bypass first header line
    
    sscanf(line, "%31s,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f", &Initial_Guess[z].ImageName, &Initial_Guess[z].x1, ... (etc....)
    So I get the ImageName correct and can load the image using OpenCV, however all my parameters come back as 0.0000...

    I also tried splitting it up

    Code:
    char line2[180];
    sscanf(line, "%31s,%s", &Initial_Guess[z].ImageName, line2);
    
    and then sscanf on line2 but no good,... if I debug and look at "line2" it IS the rest of the line from the csv... here is the definition of the struct if that helps"

    Code:
    typedef struct
    {
       char ImageName [ 180 ];
       float  x1, y1, z1, roll1, pitch1, yaw1, x2, y2, z2, roll2, pitch2, yaw2;
       CvPoint BoxUL, BoxLR;
    } RECORD_T38;
    
    And yes, all the images names are exactly the same length, so 31 works good...

    Thoughts?

    Thanks in advance.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice