Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2 41.3 25
- 2 46.2 30
- 2 51.5 40
- 2 56.7 45
- 3 49.5 525
- 3 46.2 450
- 3 54.0 575
- 3 59.5 650
- 5 36.0 500
- 5 39.0 525
- 5 31.8 480
- 5 36.4 520
- void my_code()
- {
- FILE *pfile;
- int ball[150];
- float energy[150], channel[150];
- int ball1[150], i=0;
- float energy1[150], channel1[150];
- pfile = fopen("./ascii.txt","r");
- if (!pfile) continue;
- while(!feof(pfile))
- {
- fscanf(pfile,"%dt%ft%f",&ball[0],&energy[0],&channel[0]);
- ball1[i]=ball[0];
- energy1[i]=energy[0];
- channel1[i]=channel[0];
- cout<<i<<"n";
- cout<<ball1[i]<<" "<<" "<<energy1[i]<<" "<<channel1[i]<<"n";
- i++;
- }
- }
- while(true)
- {
- fscanf(pfile,"%dt%ft%f",&ball[0],&energy[0],&channel[0]);
- if (feof(pfile)) break;
- ball1[i]=ball[0];
- energy1[i]=energy[0];
- channel1[i]=channel[0];
- cout<<i<<"n";
- cout<<ball1[i]<<" "<<" "<<energy1[i]<<" "<<channel1[i]<<"n";
- i++;
- }
- if (!pfile) continue;
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <string>
- //...
- void my_code()
- {
- std::ifstream file( "./ascii.txt" );
- std::string line;
- while ( std::getline( file, line ) )
- {
- std::istringstream is( line );
- int v1;
- float v2, v3;
- if ( is >> v1 )
- {
- std::cout << v1;
- if ( is >> v2 )
- {
- std::cout << ' ' << v2;
- if ( is >> v3 )
- {
- std::cout << ' ' << v3;
- }
- }
- std::cout << std::endl;
- }
- }
- }
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <string>
- //...
- void my_code()
- {
- const size_t N = 143;
- int ball[N] = {};
- float energy[N] = {};
- float channel[N] = {};
- std::ifstream file( "./ascii.txt" );
- std::string line;
- size_t i = 0;
- while ( i < N && std::getline( file, line ) )
- {
- std::istringstream is( line );
- if ( is >> ball[i] )
- {
- std::cout << ball[i];
- if ( is >> energy[i] )
- {
- std::cout << ' ' << energy[i];
- if ( is >> channel[i] )
- {
- std::cout << ' ' << channel[i];
- }
- }
- std::cout << std::endl;
- }
- }
- }
- while (!feof(fp)) {
- ...
- ret = fscanf(pfile,"%dt%ft%f",&ball[0],&energy[0],&channel[0]);
- if (ferror(fp) || (ret == EOF)) {
- // handle the error
- break;
- }
- ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement