fscanf on sun's

This is a discussion on fscanf on sun's within the C Programming forums, part of the General Programming Boards category; hi, have read of compatibility problems with fscanf. I have written a program which uses fscanf on windows. When I ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    23

    fscanf on sun's

    hi,

    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
    Posts
    523
    if you have a fixed length record or if the records are seperate with a newline you could try fgets and sscanf.
    Code:
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    > 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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21