Re: openning a file
- From: Ben Bacarisse <ben.usenet@xxxxxxxxx>
- Date: Wed, 06 Aug 2008 02:20:22 +0100
xiao <littledddna@xxxxxxxxx> writes:
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
It is best not to quote sig blocks (unless you are talking about them).
Ok guys , i decided to write it again like this:
34 #include <stdlib.h>
What's in the other 33 lines?
35 #include <stdio.h>
36 #include <string.h>
37 float **Allocate2DFloat(int rows, int columns)
Missing semicolon ';' at the end.
38
39 int main()
40 {
41 FILE *lat,*lon;
42 int i,j;
43 float **latitude;
44
45 lat =
fopen("MOD021KM.A2005243.0255.005.2008027115345.lat", "r");
46 lon =
fopen("MOD021KM.A2005243.0255.005.2008027115345.lon", "r");
47
48 latitude=Allocate2DFloat(nrows, ncolumns);
Are these two variable defined in the missing 33 lines?
If you don't start testing the result from things that can fail,
people will lose patience. At the very least put all the work inside
an if (lat && lon && latitude) { ... }. You know, there are languages
that throw exceptions, and you may prefer one of them -- C need lots
of tests that things worked.
49
50
51 for(i=0; i<nrows; i++){
52 for(j=0; j<ncolumns; j++){
53
54 latitude[i][j] = 0.0;
55
56 }
57 }
Aren't you going to read values into this array?
58
59
60 for(i=0; i<nrows; i++){
61 fread(latitude[i],sizeof(float),ncolumns,lat);
62 }
63 close(lat);
64 return(0);
65 }
66 /* Function to create a 2D float array of pointers*/
67
68 float **Allocate2DFloat(int rows, int columns)
69 {
70 float **pntr;
71
72
73 pntr = (float **)malloc(sizeof(float*)*rows);
74 pntr[0] = (float *)malloc(sizeof(float)*rows*columns);
You don't need the casts, but you do need to check the result.
75 for(i=1; i<rows; i++)pntr[i] = pntr[i-1]+columns;
76 return pntr;
77 }
But it saids:
ReadClassFiletest.c: In function `Allocate2DFloat':
ReadClassFiletest.c:40: warning: 'main' is usually a function
ReadClassFiletest.c:40: error: syntax error before '{' token
ReadClassFiletest.c:45: error: syntax error before "lat"
Why is that? :(
The missing ;.
--
Ben.
.
- References:
- openning a file
- From: xiao
- Re: openning a file
- From: Eric Sosman
- Re: openning a file
- From: xiao
- Re: openning a file
- From: Willem
- Re: openning a file
- From: xiao
- Re: openning a file
- From: Willem
- Re: openning a file
- From: Johannes Bauer
- Re: openning a file
- From: xiao
- Re: openning a file
- From: CBFalconer
- Re: openning a file
- From: Keith Thompson
- Re: openning a file
- From: Richard Heathfield
- Re: openning a file
- From: xiao
- openning a file
- Prev by Date: Re: openning a file
- Next by Date: Re: openning a file
- Previous by thread: Re: openning a file
- Next by thread: Re: openning a file
- Index(es):
Relevant Pages
|