Thread: sscanf does'nt parse a simple file correctly

  1. #1
    Registered User
    Join Date
    Feb 2008

    sscanf does'nt parse a simple file correctly

    Hi, here's the first example

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

    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],
    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]);

    Can anyone see a problem with that sscanf statement?


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

    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
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    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
    To be or not to be == true

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