Thread: fscanf on sun's

  1. #1
    Registered User
    Join Date
    Apr 2002

    fscanf on sun's


    have read of compatibility problems with fscanf. I have written a program which uses fscanf on windows. When I ran it on linux it worked fine. However I'm wanting to mainly use it on solaris (sun os) and for some reason it dosent work :-(

    Have definetly isolated the problem as fscanf and it returns a bus error. Was wondering if you could point me in the right direction, if there is another function to use how would you get the same functionality as fscanf eg fscanf allows %d and %s seperated by comas extensively(i.e. fscanf(f,"%d , %d , %s , %d",%v,&x,&y,&z)

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    if you have a fixed length record or if the records are seperate with a newline you could try fgets and sscanf.
    char buffer[ 100 ];
    fgets( buffer, sizeof( buffer ), file );
    sscanf( buffer, "%d , %d , %s , %d", &v, &x, y, &z );
    I suggest you look up fgets in your documentation, it may or may not work for you.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > I have written a program which uses fscanf on windows
    The most likely cause of the problem is your code.

    Just because it happens to work (or more likely appears to work) does not mean that it is bug free.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf causes a SEGMENTATION FAULT
    By yougene in forum C Programming
    Replies: 15
    Last Post: 12-28-2008, 11:11 PM
  2. fscanf in different functions for the same file
    By bchan90 in forum C Programming
    Replies: 5
    Last Post: 12-03-2008, 08:31 PM
  3. fscanf causing a crash
    By dougwilliams in forum C Programming
    Replies: 6
    Last Post: 11-18-2007, 03:52 PM
  4. fscanf help
    By Axel in forum C Programming
    Replies: 13
    Last Post: 10-22-2006, 10:44 PM
  5. Using fscanf with a structure
    By daluu in forum C Programming
    Replies: 10
    Last Post: 10-11-2004, 01:32 PM
Website Security Test