Thread: sscanf does'nt parse a simple file correctly

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    5

    sscanf does'nt parse a simple file correctly

    Hi, here's the first example

    http://pastebin.com/d5e48e200

    linje from vue is the text file,
    the other linje is sscanf(); which i use like this:

    gettjamem(objnr,i);
    sscanf(line,"%s %f %f %f %f %f %f",&tmpline,&cameras[objnr].source_x[i],&cameras[objnr].source_y[i],&cameras[objnr].source_z[i],
    &cameras[objnr].target_x[i],&cameras[objnr].target_y[i],&cameras[objnr].target_z[i]);
    printf("linjen fra VUE: %s\n", &line);
    printf("frame: %i cam?: %s",i, &tmpline);
    printf("X: %f Y: %f\n",cameras[objnr].source_x[i],cameras[objnr].source_y[i]);
    i++;

    Can anyone see a problem with that sscanf statement?

    thx,
    seidel.

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,670
    One thing I see: Assuming tmpline is a character array which has been properly allocated...as a string, it should be passed without the address-of operator.

    Code:
    sscanf(line, "%s %f...", tmpline, &cameras[objnr].source_x[i]...);
    But looking at the pastebin, it appears your parsing is off anyway. You probably need to revisit the manual for sscanf.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    when using %s format - you need to pass a pointer to the string
    because buffer - is array of chars - you do not need to use & before it...

    To make a more full check - you need to post variable declarations as well
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  3. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  4. Help on simple file functions
    By enjoyincubus in forum C Programming
    Replies: 20
    Last Post: 12-01-2006, 04:41 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM