karl@wiliki.eng.hawaii.edu (Karl Ihrig) (05/27/91)
I am writing a data analysis program, my first big project in C, or any language for that mater. I take an ascii data file from a spreadsheet, and put it into a string. Then from the string I put it all in a structure, which has strings for the column names and a 2 dimensional float array for the numerical data. My problem is that there are blank spots in my real world data. I am totally baffled. How do I mark the float element of the array as null, blank, or not available? Karl Enrique Ihrig karl@wiliki.eng.hawaii.edu
henry@zoo.toronto.edu (Henry Spencer) (05/28/91)
In article <13223@uhccux.uhcc.Hawaii.Edu> karl@wiliki.UUCP (Karl Ihrig) writes: >...blank spots in my real world data. I am totally baffled. How do I >mark the float element of the array as null, blank, or not >available? There is no portable way except allocating a separate flag for each of your float values. C does not guarantee the existence of any "blank" value in floating point, and indeed a good many machines have no such special value. If you are willing to constrain your code to run on machines using IEEE floating point, you could use a NaN value... but there is no standard way of generating such a value or testing for it. -- "We're thinking about upgrading from | Henry Spencer @ U of Toronto Zoology SunOS 4.1.1 to SunOS 3.5." | henry@zoo.toronto.edu utzoo!henry
gtephx (Wild Rider) (05/29/91)
In article <1991May28.153655.24199@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: >In article <13223@uhccux.uhcc.Hawaii.Edu> karl@wiliki.UUCP (Karl Ihrig) writes: [ ... description of reading data from a spreadsheet file ... ] >>...blank spots in my real world data. I am totally baffled. How do I >>mark the float element of the array as null, blank, or not >>available? > >There is no portable way except allocating a separate flag for each of >your float values. C does not guarantee the existence of any "blank" value >in floating point, and indeed a good many machines have no such special >value. If you are willing to constrain your code to run on machines using >IEEE floating point, you could use a NaN value... but there is no standard >way of generating such a value or testing for it. although henry did directly answer karl's question, perhaps karl could do better by reevaluating what he's trying to do, i.e., is the chosen data structure appropriate for a spreadsheet? since spreadsheets usually resemble a sparse matrix, i would rather choose something like: typedef struct row { int rowNum; struct col * colPtr; } Row; typedef struct col { int colNum; float cellValue; struct col * nextCol; } Col; ... Row * masterPtr = NULL; ... >-- >"We're thinking about upgrading from | Henry Spencer @ U of Toronto Zoology >SunOS 4.1.1 to SunOS 3.5." | henry@zoo.toronto.edu utzoo!henry ^^^^^^^^^^^^^^^^^^^^^^^^^^ is that pronounced "SunToast" ? :-) cheers, wr (wild rider) -- Wallace Roberts, AG (formerly GTE) Communication Systems, Phoenix, AZ UUCP: ...!{ncar!noao!asuvax | uunet!zardoz!hrc | att}!gtephx!robertsw Internet: gtephx!robertsw@asuvax.eas.asu.edu Bike: '82 GS1100L Suz voice: (602)581-4555 fax: (602)582-7624 Cage: '89 Mustang GT
bhoughto@pima.intel.com (Blair P. Houghton) (05/29/91)
In article <1991May28.153655.24199@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: >In article <13223@uhccux.uhcc.Hawaii.Edu> karl@wiliki.UUCP (Karl Ihrig) writes: >>...blank spots in my real world data. I am totally baffled. How do I >>mark the float element of the array as null, blank, or not >>available? > >There is no portable way except allocating a separate flag for each of >your float values. C does not guarantee the existence of any "blank" value Another idea is to keep the 2-d array of floating point numbers, and in the spreadsheet cells keep pointers to the members of the array. Then you can use a null pointer to indicate a blank cell. This roughly doubles the memory usage of that array, and complicates a considerable amount of your floating-point computations with pointer references, but it does provide the important feature you desire. --Blair "There's got to be a way to get back homeward..." -Lennon & McCartney