Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. 2 41.3 25
  2. 2 46.2 30
  3. 2 51.5 40
  4. 2 56.7 45
  5. 3 49.5 525
  6. 3 46.2 450
  7. 3 54.0 575
  8. 3 59.5 650
  9. 5 36.0 500
  10. 5 39.0 525
  11. 5 31.8 480
  12. 5 36.4 520
  13.  
  14. void my_code()
  15. {
  16. FILE *pfile;
  17. int ball[150];
  18. float energy[150], channel[150];
  19. int ball1[150], i=0;
  20. float energy1[150], channel1[150];
  21. pfile = fopen("./ascii.txt","r");
  22. if (!pfile) continue;
  23. while(!feof(pfile))
  24. {
  25. fscanf(pfile,"%dt%ft%f",&ball[0],&energy[0],&channel[0]);
  26. ball1[i]=ball[0];
  27. energy1[i]=energy[0];
  28. channel1[i]=channel[0];
  29. cout<<i<<"n";
  30. cout<<ball1[i]<<" "<<" "<<energy1[i]<<" "<<channel1[i]<<"n";
  31. i++;
  32. }
  33. }
  34.  
  35. while(true)
  36. {
  37. fscanf(pfile,"%dt%ft%f",&ball[0],&energy[0],&channel[0]);
  38. if (feof(pfile)) break;
  39. ball1[i]=ball[0];
  40. energy1[i]=energy[0];
  41. channel1[i]=channel[0];
  42. cout<<i<<"n";
  43. cout<<ball1[i]<<" "<<" "<<energy1[i]<<" "<<channel1[i]<<"n";
  44. i++;
  45. }
  46.  
  47. if (!pfile) continue;
  48.  
  49. #include <iostream>
  50. #include <fstream>
  51. #include <sstream>
  52. #include <string>
  53.  
  54. //...
  55.  
  56. void my_code()
  57. {
  58. std::ifstream file( "./ascii.txt" );
  59.  
  60. std::string line;
  61.  
  62. while ( std::getline( file, line ) )
  63. {
  64. std::istringstream is( line );
  65. int v1;
  66. float v2, v3;
  67.  
  68. if ( is >> v1 )
  69. {
  70. std::cout << v1;
  71. if ( is >> v2 )
  72. {
  73. std::cout << ' ' << v2;
  74. if ( is >> v3 )
  75. {
  76. std::cout << ' ' << v3;
  77. }
  78. }
  79. std::cout << std::endl;
  80. }
  81. }
  82. }
  83.  
  84. #include <iostream>
  85. #include <fstream>
  86. #include <sstream>
  87. #include <string>
  88.  
  89. //...
  90.  
  91. void my_code()
  92. {
  93. const size_t N = 143;
  94. int ball[N] = {};
  95. float energy[N] = {};
  96. float channel[N] = {};
  97.  
  98. std::ifstream file( "./ascii.txt" );
  99.  
  100. std::string line;
  101.  
  102. size_t i = 0;
  103. while ( i < N && std::getline( file, line ) )
  104. {
  105. std::istringstream is( line );
  106.  
  107. if ( is >> ball[i] )
  108. {
  109. std::cout << ball[i];
  110. if ( is >> energy[i] )
  111. {
  112. std::cout << ' ' << energy[i];
  113. if ( is >> channel[i] )
  114. {
  115. std::cout << ' ' << channel[i];
  116. }
  117. }
  118. std::cout << std::endl;
  119. }
  120. }
  121. }
  122.  
  123. while (!feof(fp)) {
  124. ...
  125. ret = fscanf(pfile,"%dt%ft%f",&ball[0],&energy[0],&channel[0]);
  126.  
  127. if (ferror(fp) || (ret == EOF)) {
  128. // handle the error
  129. break;
  130. }
  131. ...
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement