I want to read the matrix of a large set of points in a .txt file or the Cartesian coordinates in some such data structure. use.
The file contains content of
023 435 1.0 23.5 12.5 0.2 :::::::::::::
< P> And so on ... There are about 4000 such coordinates in the file. The first column indicates the x coordinate, the second column y and the third column z coordinate. Each line represents a point I finally want to do some computation based on coordination. The initial level of file handling in C is I
Any ideas ?? Please ASAP!
Use sscanf and gnu getline.
#defined _GNU_SOURCE #include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; # Max 5000 Typedf Structure Corp. defined {float x; Float Y; Float jade; } Coordination; Int main (int argc, char * argv []) {exit (argc! = 2) (1); Char * filename = argv [1]; Char * line = NULL; Int n = 0; FILE * coordFile = fopen (filename, "r"); Coord * coords = malloc (size (coordination) * max); If (cors == faucet) exhaust (3); Int i = 0; (Getline (and line, & amp; n, coordFile)! = -1 and i & lt; max) {int items = sscanf (line, "% f% f% f", and coords [i] .x, and coors [ii]., And the coards [ii]. Ja); If (item! = 3) exit (2); I ++; } Fclose (coordinate file); }
Comments
Post a Comment