Code works, one some files but not others

This is a discussion on Code works, one some files but not others within the C Programming forums, part of the General Programming Boards category; Thanks everyone, for all the help previously. My code is running, for some files but not for others. I've attached ...

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    9

    Unhappy Code works, one some files but not others

    Thanks everyone, for all the help previously.

    My code is running, for some files but not for others.

    I've attached six files (and the C code) to this posting. Each file has various lenghs and values.

    When I start using the code for processing, I'll have a .txt with seven years (2555 days) of data for it to loop through.


    The code runs fine with the first two files. If I run the third file, it works fine until line 59. For example:

    8 0.00 0.000 0.000 0.000 -0.000 0.000 -0.000 0.000 0.000 0.000
    59 0.000 -inf nan -inf inf nan inf -inf nan -inf
    60 0.000 nan nan nan -inf nan -inf inf nan nan
    61 0.000 nan nan nan nan nan nan nan nan nan
    62 0.000 nan nan nan nan nan nan nan nan nan

    Files four and five run fine. File 6 does not. Instead it works fine until line 201.

    200 0.000 28.336 0.000 19.991 0.000 0.000 0.000 -0.000 -0.000 0.000
    201 0.000 -8093828734616807705369824168368363488770529427456. 000 -12913579564.136 -51390762511607983407194125328182191452808282112.00 0 8093828734616807705369824168368363488770529427456. 000 12913579564.136 51390762511607983407194125328182191452808282112.00 0 -8093828734616807705369824168368363488770529427456. 000 -12913579564.136 -51390762511607983407194125328182191452808282112.00 0
    202 0.000 85368343369181595663949439458640250954538499456987 9054840307157953354082032384212992.000 544815528226548568775005951289180859584741376.000 48783214515008478275437554298480275036083149913838 034599564383102524958464540672.000 -85368343369181595663949439458640250954538499456987 9054840307157953354082032384212992.000 -544815528226548568775005951289180859584741376.000


    Any advice or suggestions? I'm getting a bit frustrated.
    Attached Files Attached Files

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,767
    You should compare the result of fscanf() with 11, not EOF

    As in
    fscanf() == 11

    Not
    fscanf() != EOF

    That way, you know you have 11 good answers.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    9
    You are right, Salem. Thanks for catching that.

    I've corrected that in my code. However, I'm still having the exact same problems as before.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Well, one problem is uninitialized variables. The first line of the file is:
    Code:
    0	1	0.00	249.06	0.46	258.58	0.58	49.02	0	0	0
    Of which the doy variable is initialized to the second value which is 1. Then you do this:
    Code:
    doy++;
    
    if((i==0) && (doy <= 1 ))
    {
        cmet = met_c_init;
        cstr = struct_c_init;
        cslw = slow_c_init;
        rmet = 0;
        rstr = 0;
        rslw = 0;
    }
    So... doy gets incremented to 2 and the code in the "if" block never gets executed and all those variable never get initialized.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    9

    Smile Ah HA!

    I found the source of error! A few times I had lower than expected Temp input, so this was causing an error in my temperature function. Fixed this problem with a if else statement.

    Thanks all!

  6. #6
    Registered User
    Join Date
    Aug 2010
    Posts
    9

    Uninit variable

    Quote Originally Posted by hk_mp5kpdw View Post
    Well, one problem is uninitialized variables. The first line of the file is:
    Code:
    0	1	0.00	249.06	0.46	258.58	0.58	49.02	0	0	0
    Of which the doy variable is initialized to the second value which is 1. Then you do this:
    Code:
    doy++;
    
    if((i==0) && (doy <= 1 ))
    {
        cmet = met_c_init;
        cstr = struct_c_init;
        cslw = slow_c_init;
        rmet = 0;
        rstr = 0;
        rslw = 0;
    }
    So... doy gets incremented to 2 and the code in the "if" block never gets executed and all those variable never get initialized.
    good eye. but perhaps doy was initialized towards the begining of code with doy=0; ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 04:01 PM
  2. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM
  3. How Do u See if a code works
    By Nos in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2005, 02:34 PM
  4. Urgent: c code to explore zip/war/ear/jar files
    By chinnu in forum C Programming
    Replies: 1
    Last Post: 09-02-2003, 04:09 AM
  5. header files and code files..
    By CompiledMonkey in forum C++ Programming
    Replies: 4
    Last Post: 02-15-2002, 09:35 AM

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