Thread: Compile/ runs on MAC but not on Windows?

  1. #1
    Registered User
    Join Date
    Dec 2013
    Posts
    1

    Compile/ runs on MAC but not on Windows?

    This code works beautifully on my Macbook (where I compiled it and it runs perfectly). However when I run it on a windows machine, it compiles but reads that the process died on "Signal 11"

    We use JGrasp in our class for everything, and I cannot find out why it wont work. I recieved a 52/100 on the assingment because it didn't work for my grader and need help disputing it. Finding out why it didnt run would hopefully be a step as to figuring out why it doesnt work.
    These are the files
    auResults2013.txt
    assign10.c

    Thanks in advance!!!!!!

    Code:
    /*************************************************************************************************
    This file takes an input file on the Auburn football season and scans all of its data into arrays. It then puts the 
    data into a printable format and calculates the records and averages and prints it to the screen. 
    ***************************************CONSTANTS**********************************************/
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <string.h>
    
    #define FILENAME    "auResults2013.txt" //input text file
    #define MAXNUMGAMES 15                  //max numer of games in a season
    #define TITLELEN    32                  //max title lenght
    #define CONFLEN     4                   //max length of conference
    #define DATELEN     10                  //length of date
    #define NAMELEN     20                  //max lenght of opponent names
    #define NUMCOLS     4                   //max number of numeric collums
    #define TIMECOL     2                   //column index of time
    #define LINE_MAX    61                  //max num of characters on a line
    
    /**************************************INPUT****************************************************/
    int readDatafile( char title[], char conf[][CONFLEN], char dates[][DATELEN], char oppNames[][NAMELEN], int results[][NUMCOLS]);
    void printReport( char title[], char conf[][CONFLEN], char dates[][DATELEN], char oppNames[][NAMELEN], int results[][NUMCOLS], int numGames);
    void printHeader( char title[], char dates[][DATELEN], int numGames);
    
    //my created functions for calculations
    int arrayAverage(int numGames, int results[][NUMCOLS] );
    double auaverageScore(int numGames, int results[][NUMCOLS] );
    double oppAverageScore(int numGames, int results[][NUMCOLS] );
    void compareGameLenghts(char dates[][DATELEN], int results[][NUMCOLS], int numGames);
    
    int main()
    {
       char title[LINE_MAX],
            conf[MAXNUMGAMES][CONFLEN],
            dates[MAXNUMGAMES][DATELEN],
            oppNames[MAXNUMGAMES][NAMELEN];
         
       int  results[MAXNUMGAMES][NUMCOLS],
            numGames;
            
      
       numGames = readDatafile(title, conf, dates, oppNames, results);
       printReport(title, conf, dates, oppNames, results, numGames);      
       
       
         
       return 0;
    }
    
    //---------------------------------------------------Read Data-----------------------------------------
    int readDatafile(char title[], char conf[][CONFLEN], char dates[][DATELEN], char oppNames[][NAMELEN], int results[][NUMCOLS])
    {
       char lineNumber[LINE_MAX];
       int  timeScanner[MAXNUMGAMES][TIMECOL],
       l,   //line number counter
       c,   //collumn number
       t;   //time scanner counter
       
       FILE *inp = fopen(FILENAME, "r");  
     
       if(inp == NULL) {printf("There is no input file");}
       
       else
       {
          fgets(title,TITLELEN,inp);
          
          //scan Conference, Date of Game, and Opponent's Names in
          while(fscanf(inp,"%s%s%s", conf[l], dates[l], oppNames[l]) !=EOF)
          {
            
             //Scan score in and store in array
             fscanf(inp, "%d %d", &results[l][0], &results[l][1]);
          
             //Scan hours and minutes in
             fscanf(inp, "%d:%d", &timeScanner[l][0], &timeScanner[l][1]);
          
             //Compute hours into minues, add, and store into returned array
             results[l][2] = (timeScanner[l][0]*60 + timeScanner[l][1]);
          
             //Scans attendance
             fscanf(inp," %d", &results[l][3]);
             
             l++;
          }
            
          fclose(inp);
       }
       return (l); //returns number of games in counter
       
    }
    /*****************************************************OUTPUT************************************************************/
    
    //-------------------------------------------------PRINT REPORT--------------------------------------------------------//
    void printReport( char title[], char conf[][CONFLEN], char dates[][DATELEN], char oppNames[][NAMELEN], int results[][NUMCOLS], int numGames)
    {
       int c,   //line counter
           w=0, // win counter
           l=0, //loss counter
           attdAvg;
       double auScoreAvg,
              oppScoreAvg,
              dAU,
              dOPP;
       char compare[CONFLEN] = "SEC";
       
       //print Top of Chart
       printHeader(title, dates, numGames);
      
       //calculates average attendance for use later
       attdAvg = arrayAverage(numGames, results);
       
       //averages auburns scores, returns the averagre as an int
       auScoreAvg  = auaverageScore(numGames, results);
       
       //averages Opponent scores, returns the averagre as an int
       oppScoreAvg = oppAverageScore(numGames, results);
      
       //prints each line in the chart with game data
       for(c=0; c<numGames; c++)
       {
          if(strcmp (conf[c],compare) == 0) {printf("* ");}
          else {printf("  ");}
       
       
          printf( "%s %-20s  ",dates[c], oppNames[c]); //prints the date and opponents name
          
          dAU = results[c][0];
          printf("%2.0lf-", dAU); //prints the Auburn score 
          
          dOPP = results[c][1];
          printf("%2.0lf", dOPP); //and the opponents score per line
       
       
          if(results[c][0] > results[c][1]) //determines if AU win
          {
             printf(" W ");
             w++;
          }
          
          if(results[c][1] > results[c][0]) //determines if AU loss
          {
             printf(" L ");
             l++;
          }
          
          printf(" %6d ", results[c][3]);   //prints attendence
          
          if(attdAvg < results[c][3]) {printf(" +\n");} //determine if attendace is above the avg
          else{printf("\n");}
       }
       
       
       printf("\n");
       printf("* SEC conference game\n");
       printf("+ Above Average Attendance\n");
       printf("\n");
       printf("Auburn Season Record:    %d-%d\n", w, l);
       printf("Auburn Average Score:    %3.1lf\n", auScoreAvg);
       printf("Opponent Average Score:  %3.1lf\n", oppScoreAvg);
       compareGameLenghts(dates, results, numGames); //finds and prints the longest game and date
    
    
    }
    
    
    //-------------------------------------------------Print Headers---------------------------------------------------
    void printHeader( char title[], char dates[][DATELEN], int numGames)
    {
       int x = numGames - 1;
       //printf("%d", x);
       printf("\n");
       printf(" %s as of %s \n\n", title, dates[x]);
       printf("                                  SCORE W\n");
       printf("    DATE          OPPONENT        AU-OP L  ATTEND\n");
       printf("--------------------------------------------------\n");
    }
    
    //----------------------------------------------Average Attendence------------------------------------------------
    int arrayAverage(int numGames, int results[][NUMCOLS] )
    {int num, //counter
         total, //total num ppl
         average; //total average for all games
    
       for(num=0 ; num<numGames; num++)
       {
          total += results[num][3];//sums attendence
       }
    
       average = total/numGames; //calculates average attendence
     
       return average;
    }
       //-----------------------------------------------Calculate AU Average Score--------------------------------------------
    double auaverageScore(int numGames, int results[][NUMCOLS] )
    {
       double average, 
              total;     //sum of all scores
       int    c;         //counter 
            
       for(c=0; c<numGames; c++)
       {
          total += results[c][0];
       }
            
       average = total/numGames; 
       
       return average; 
    }
    //--------------------------------------------------Calculate Opp Avg Score--------------------------------------------------
    double oppAverageScore(int numGames, int results[][NUMCOLS] )
    {
       double average,   
              total=0;   //keeps track of total of opp scores
       int    c;         //counter
            
       for(c=0; c<numGames; c++)
       {
          total += results[c][1];
       }
            
       average = total/numGames; //averages opponets socores/ game
       return average; 
    }
    //--------------------------------------------------Finds longest Game-----------------------------------------------------
    void compareGameLenghts(char dates[][DATELEN], int results[][NUMCOLS], int numGames )
    {
       int k, maxK; //counter, counter of max time
       double maxD; //numeric value of time of longest date
      
       maxD = results[0][2];
       for(k=0; k<numGames; k++ )
       {
          if(results[k][2] > results[0][2]) //compares  game time lenghts
          {
             maxD = results[k][2];
             maxK = k;
          }
       }
      
       printf("Longest Games was %3.0lf mins on %s\n", maxD, dates[maxK]);
    }
    Attached Files Attached Files
    Last edited by Salem; 12-02-2013 at 11:53 PM. Reason: Pasted clean copy of the code

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    It seems the formatting of your text is a little messed up. I would fix that first. For example, the spacing in the left column has been replaced by garbage characters. If you're pasting code here you need to just paste plain text without any rich text formatting.

  3. #3
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Just because it worked on one machine does not mean it's correct.

    In your case, you've forgotten to initialize l (bad variable name, by the way, since it looks like a 1) to 0 when reading in the lines. Apparently on the Mac system it happened to be 0 but on the MS system you weren't so lucky. Welcome to the wacky world of programming!

    Also, many of your lines are tooooooooooooooooooooooooooooo long; try to limit them to 80 chars or less.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  4. #4
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    There are more unitialised variables than l. Consider what happens when there is no input file, for example.

    Actually, we don't have to imagine it we can just run it

    Code:
    $ valgrind ./a.out 
    ==2207== Memcheck, a memory error detector
    ==2207== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
    ==2207== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
    ==2207== Command: ./a.out
    ==2207== 
    There is no input file
    ==2207== Conditional jump or move depends on uninitialised value(s)
    ==2207==    at 0x3E55E48DF9: vfprintf (in /usr/lib64/libc-2.17.so)
    ==2207==    by 0x3E55E51E38: printf (in /usr/lib64/libc-2.17.so)
    ==2207==    by 0x400D4C: printHeader (thingy.c:176)
    ==2207==    by 0x400A0F: printReport (thingy.c:111)
    ==2207==    by 0x4007BA: main (thingy.c:47)
    ==2207== 
    ==2207== Conditional jump or move depends on uninitialised value(s)
    ==2207==    at 0x3E55E48BBA: vfprintf (in /usr/lib64/libc-2.17.so)
    ==2207==    by 0x3E55E51E38: printf (in /usr/lib64/libc-2.17.so)
    ==2207==    by 0x400D4C: printHeader (thingy.c:176)
    ==2207==    by 0x400A0F: printReport (thingy.c:111)
    ==2207==    by 0x4007BA: main (thingy.c:47)
    ==2207== 
    ==2207== Use of uninitialised value of size 8
    ==2207==    at 0x3E55E48DF9: vfprintf (in /usr/lib64/libc-2.17.so)
    ==2207==    by 0x3E55E51E38: printf (in /usr/lib64/libc-2.17.so)
    ==2207==    by 0x400D4C: printHeader (thingy.c:176)
    ==2207==    by 0x400A0F: printReport (thingy.c:111)
    ==2207==    by 0x4007BA: main (thingy.c:47)
    ==2207== 
      as of  
    
                                      SCORE W
        DATE          OPPONENT        AU-OP L  ATTEND
    --------------------------------------------------
    ==2207== Conditional jump or move depends on uninitialised value(s)
    ==2207==    at 0x400DA4: arrayAverage (thingy.c:188)
    ==2207==    by 0x400A20: printReport (thingy.c:114)
    ==2207==    by 0x4007BA: main (thingy.c:47)
    ==2207== 
    ==2207== 
    ==2207== Process terminating with default action of signal 8 (SIGFPE)
    ==2207==  Integer divide by zero at address 0x4030209C3
    ==2207==    at 0x400DAA: arrayAverage (thingy.c:193)
    ==2207==    by 0x400A20: printReport (thingy.c:114)
    ==2207==    by 0x4007BA: main (thingy.c:47)
    ==2207== 
    ==2207== HEAP SUMMARY:
    ==2207==     in use at exit: 0 bytes in 0 blocks
    ==2207==   total heap usage: 1 allocs, 1 frees, 568 bytes allocated
    ==2207== 
    ==2207== All heap blocks were freed -- no leaks are possible
    ==2207== 
    ==2207== For counts of detected and suppressed errors, rerun with: -v
    ==2207== Use --track-origins=yes to see where uninitialised values come from
    ==2207== ERROR SUMMARY: 5 errors from 4 contexts (suppressed: 2 from 2)
    Floating point exception
    I'm guessing the floating point exception is caused by having a value of 0 for numGames (in the average functions)

    Edit 2: Seems as though it doesn't work on Linux either (with the input file)
    Code:
    $ ./a.out 
    
     2013 AUBURN TIGERS Game Results as of 09Nov2013 
    
                                      SCORE W
        DATE          OPPONENT        AU-OP L  ATTEND
    --------------------------------------------------
                            1438787480-62 W       0  +
      ~� �                     0- 0     62  +
      �                      2114097616-32767 W   32767  +
       +                     2090266759- 0 W      62  +
      `%�U>                      -1- 0 L      62  +
      �U> 
                         1440812008-62 W   32761  +
      > ���U>                 2114098080-32767 W      62  +
       >                      0-32761 L       0  +
       .N=�                   0- 0  32767  +
       >                      0-32 L       0  +
       8�U>                  0- 0      0  +
       �                     1- 0 W      62  +
                             1436551760-62 W       0  +
      
      ~� �                    1436550176-62 W      62  +
      > H@                   2114098080-32767 W      62  +
                             1-32767 L       0  +
      p�~�                        0-32767 L   32761  +
      ~� �                     3-40 L      15  +
       ���U>                  3-14 L      43  +
       �                     3-32 L      39  +
      ��~�                       3-46 L       7  +
      �U>                        3-10 L       2  +
      � ▒s�U>                 26577600- 0 W      62  +
      UBURN TIGERS Game Results >                     2114098208-32767 W      62  +
      RS Game Results .N=�                   1- 0 W       0  +
      sults                       -163754450- 0 L      62  +
       X��4�                1438787480-62 W   32767  +
       TIGERS Game Results   1440758560-62 W      62  +
      `@ �                     2114098288-32767 W   32767  +
      ~�                       46- 0 W   32767  +
      H                        0- 0  32761  +
       >                     881100376-32761 W       0  +
                             1440812296-62 W       0  +
      ~�                        0- 1 L       1  +
       ��~�                 0-32767 L   32767  +
                             2114098432-32767 W       0  +
      �P-RED,`@ SEC                   881101720-32761 W      62  +
      @ USA                   1438786056-62 W      62  +
      � �                      0- 0  32761  +
       .E                    1-32767 L       0  +
      �P�{▒���PAC                       1- 0 W      62  +
      C                      11538501- 0 W       0  +
      SEC �                     2114773464-32767 W      62  +
      U }T                    0- 0     62  +
      SEC #                     2114098288-32767 W   32767  +
                            -163754450- 0 L       0  +
      gL i�~31Aug2013         -1- 0 L   32767  +
       013                   1440809272-62 W   32761  +
      ▒ 013                   858861618-1112883488 L  1162299732  +
       013                   1193300818-543518049 W  7566444  +
      # 013                   191- 0 W       0  +
       013                   4198240- 0 W       0  +
      � ��~�                2114098608-32767 W      72  +
       �                     0- 0     62  +
      �H ��~�                 0- 0  32767  +
       �                     0- 1 L       0  +
      - ��~�                 0- 0 742671647  +
       �                    4195936- 0 W   32767  +
       y�~�                 0- 0      0  +
       �                    2079150246--742737638 W  5133651  +
      � ��~�                4408659-4408659 5590867  +
      ~� �                    4408659-4281173 W  4408659  +
      31Aug2013 WASHINGTON_STATE      31-24 W   85095  +
      07Sep2013 ARKANSAS_STATE        38- 9 W   83246  +
    * 14Sep2013 MISSISSIPPI_STATE     24-20 W   85817  +
    * 21Sep2013 LSU                   21-35 L   92638  +
    * 05Oct2013 OLE_MISS              30-22 W   86504  +
      12Oct2013 WESTERN_CAROLINA      62- 3 W   84171  +
    * 19Oct2013 Texas_A&M             45-41 W   87165  +
      26Oct2013 FLORIDA_ATLANTIC      45-10 W   85517  +
    * 02Nov2013 Arkansas              35-17 W   66835  +
    * 09Nov2013 at_Tennessee          55-23 W  102455  +
    
    * SEC conference game
    + Above Average Attendance
    
    Auburn Season Record:    42-19
    Auburn Average Score:    551275208.7
    Opponent Average Score:  12817762.8
    Longest Games was 2114098608 mins on
    Last edited by Hodor; 12-02-2013 at 06:24 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code runs on Windows 7 but not Vista?
    By gken05 in forum C++ Programming
    Replies: 7
    Last Post: 05-23-2011, 12:51 PM
  2. Replies: 6
    Last Post: 09-18-2010, 08:45 PM
  3. Runs in Windows but not un Linux (Ubuntu)
    By Joelito in forum C++ Programming
    Replies: 5
    Last Post: 07-29-2009, 06:49 PM
  4. how do i compile pipe() API on windows ?
    By intruder in forum C++ Programming
    Replies: 2
    Last Post: 01-04-2006, 06:39 PM
  5. windows installer for psp runs for vs6
    By iain in forum Tech Board
    Replies: 1
    Last Post: 06-27-2004, 09:21 AM