- Where Developers Learn, Share, & Build Careers


I have a text file of approximately 2000 lines, which is created like this:

1 1 Name 1 Last N 1 58C 1600 1310.40 6 1 0.22 2164.80 1
2 1 Name 2 Last N 2 22D 1700 1523.37 4 1 0.13 897.26 1 1 3 3 Name 3 Last N 3 34 C 1600 11 9 5.84 2 1 0.26 836.16 1


2000 3 NameX LastNX 46 d 6000 6000.00 1 0 0.00 0.00 1

What I want to do is read all those values ​​from the text file and store them in arrays:

  Integer ID [2100]; Four numerals [2100] [30]; Four Applesido [2100] [30]; Int Adad [2100]; Int Pusto [2100]; Four citogora [2100]; Int'l Sealdo I [2100]; Float Sulemo A [2100]; Int antigezed [2100]; Intentitro [2100]; Float Airport [2100]; Float Ahoro [2100]; Intibre Libre [2100];   

But when I am trying to read them, I got lots of garbage in the console

The way I am trying to read and store them In arrays:

  // path no. 1 four line [70]; While (fgets (line, 70, data)! = Null) {flush (;); Sscanf (line, "% d% d% s% s% d% c% d% f% d% d% f% f% d \ n", and id [i], & amp; pusho [i] , & Amp;; nombre [i], & apellido [i], & edad [i], & categoria [i], & sueldoI [i], & sueldoA [i], & Amp; antiguedad [i], & inscrito [i], & aporte [i], & ahorro [i], & amp; Libre [i]); I ++; } // They are number 2, the way I like the line here, but I can not find a way to split the string into several values ​​I need to store in arrays (fgets (linea, 70 , Data)! = Null) {printf ("% s", line); }   

This is the first method I get:

Way # 1 Output

Edit:

I modified the size of arrays from 2100 to 2000 and the program is better

Delete the address operator from & nombre [i] , And and epilido [i] , they are arrays and you can use an array name without address to find the first element:

Ub> sscanf (/ *********************************************************************************************** ******************** In addition, for strings, you should specify the expected string length in the scan (The size of your array -1):

  sscanf (line, "...% 29s% 29s ....", / ***, nombre [i], apalido [i ], / ***);   

And you may be misused i :

  int main () {char linea [70]; File * data = FOPN ("data", "R"); Int i = 0; While (fgets (line, 70, data)! = Null) {sscanf (line, "% d% d% 29s% 29s% d% c% d% f% d% d% f% f% d \ n", & Amp; i And antiguidad [ii], and inscrito [ii], and aportui [ii], and ahora [ii], and Libre [ii]); I ++; } I--; For (; i & gt; = 0; i--) {printf ("% d% s \ n", id [i], numbre [i]); } Return 0; }    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -