home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / c / 13707 < prev    next >
Encoding:
Text File  |  1992-09-15  |  3.3 KB  |  122 lines

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!swrinde!gatech!psuvax1!psuvm!gnr100
  2. From: GNR100@psuvm.psu.edu
  3. Newsgroups: comp.lang.c
  4. Subject: Floating Point Formats Not Linked
  5. Message-ID: <92259.181508GNR100@psuvm.psu.edu>
  6. Date: 15 Sep 92 22:15:08 GMT
  7. Organization: Penn State University
  8. Lines: 112
  9.  
  10.  
  11.   Hi.  I'm having a problem with double-precision numbers.I can't get scanf()
  12. to read them in.  I know about using %lf, I know about the '&', and I checked
  13. the declaration statements.The compiler doesn't complain, but the program
  14. crashes as soon as it gets to 'scanf("%lf", &matrix[ROW] [COL]);'
  15. I am only posing a portion of the copde to save space, but if you would like
  16. to see the rest, let me know and I will gladly send it out.
  17.  
  18.               all help appreciated,
  19.                   Gordon Rogers
  20.                   gnr100@psuvm.psu.edu
  21. /*----------------------BEGIN CODE ---------------------------------*/
  22. #include <stdio.h>
  23. #define MAX 5
  24.  
  25.  
  26. /*
  27.    define macros for use in array subscrpits, to simplify using cell
  28.    zero as row or column one.
  29. */
  30.  
  31. #define ROW  (row-1)
  32. #define COL  (col-1)
  33. #define PASS (pass-1)
  34.  
  35.  
  36. /*
  37.   set up macros to declare matrices, making the size
  38.   both more clear and easier to modify
  39. */
  40.  
  41. #define AROWLIM MAX
  42. #define ACOLLIM (2*MAX)
  43. #define CROWLIM MAX
  44. #define CCOLLIM 1
  45. #define BROWLIM AROWLIM
  46. #define BCOLLIM CCOLLIM
  47.  
  48.  
  49. /*
  50.    declare global variables for use in
  51.    proccessing arrays in functions
  52. */
  53.  
  54. int Arowmax;
  55. int Acolmax;  /* A will have 2x the needed columns to enable inversion */
  56. int Acolsum;  /* A will usually be processed as just the first half    */
  57.               /* Acolmax is the size of each half, Acolsum is the      */
  58.               /* actual number of columns.  This was done to simplify  */
  59.               /* parameters.                                           */
  60.  
  61. int Crowmax;
  62. int Ccolmax;
  63. int Bcolmax;
  64. int Browmax;
  65. int size;
  66.  
  67. /* Function Prototypes */
  68. get_coefficient_matrix(double matrix[AROWLIM] [ACOLLIM]);
  69.                  double B[BROWLIM] [BCOLLIM],
  70.                  double C[CROWLIM] [CCOLLIM] );
  71.  
  72. main()
  73. {
  74.  double A[AROWLIM] [ACOLLIM];
  75.  double B[BROWLIM] [BCOLLIM];
  76.  double C[CROWLIM] [CCOLLIM];
  77.  
  78.  /*
  79.    finish seting up global variables
  80.    to define matrices in parameters
  81.  */
  82.  
  83.  Ccolmax=CCOLLIM;
  84.  Bcolmax=Ccolmax;
  85.  
  86.  
  87.  get_coefficient_matrix(A);
  88. }
  89.  
  90. /*-------------------------get_coeficient_matrix()-----------------------*/
  91.  /*************************************************************************
  92.  ** The purpose of this function is to  input the coeficient matrix.     **
  93.  ** It assumes a complex matrix.                                         **
  94.  *************************************************************************/
  95. get_coefficient_matrix(double matrix[AROWLIM] [ACOLLIM])
  96. {
  97.  int row, col;
  98.  
  99.  
  100.  clrscr();
  101.  printf("\nInput the Coefficient Matrix (It must be a square matrix)");
  102.  printf("\n\n\tInput the size of the matrix (enter one integer).");
  103.  printf("\n\t\t(maximum of %d )\n\n\t\t\t", MAX);
  104.  scanf("%d", &size);
  105.  
  106.  /* define global variables for use in functions */
  107.  Arowmax=size;
  108.  Acolmax=Arowmax;
  109.  Crowmax=size;
  110.  Browmax=Arowmax;
  111.  
  112.  /* input coeficient matrix */
  113.  for (row=1; row<=size; row++)
  114.    {
  115.     for (col=1;col<=size; col++)
  116.        {
  117.         printf("\nInput element %d , %d \n", row, col);
  118.         scanf("%lf", &matrix[ROW] [COL]);
  119.        } /* end col loop */
  120.    }     /* end row loop */
  121.  }       /* end get_coeficient_matrix() */
  122.