Re: openning a file



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.
.



Relevant Pages

  • Re: openning a file
    ... 37 float **Allocate2DFloat(int rows, int columns) ... ReadClassFiletest.c:40: error: syntax error before '{' token ...
    (comp.lang.c)
  • Re: libc/printf bug
    ... I don't see that the cast should have any effect at all ... How would you print a float in hex? ... So seems printf gets confused because you present it with a float when i t wants an integer. ... This behavior I have seen in other cases where wrong or missing arguments were presented too. ...
    (comp.os.linux.development.apps)
  • Re: Comparission cause problem
    ... > I think I may be missing some points thats why, I have some doubts on the ... that is wider than a float. ... In simple terms the natural floating point type for C and C++ is double ...
    (alt.comp.lang.learn.c-cpp)
  • Re: doubles or not
    ... > even a float can not be enough for this, we may need doubles. ... the point that you are missing is "..when integers will do". ... integer math. ...
    (microsoft.public.vc.language)
  • Re: matrix stuff (solving b = A*x) --> using numerical recipes
    ... http://www.library.cornell.edu/nr/bookcpdf/c2-4.pdf p.52-54 AFAIR). ... You are missing ... float b); ... This is not a proper initialization, that is why the compiler complained. ...
    (comp.lang.c)