Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<list>
  4. #include <cctype>
  5. #define BUFFER_SIZE 46448
  6.  
  7. using namespace std;
  8.  
  9. void getFirstNames(char* unformated, std::list<std::string>* names){
  10.     int n = 0;
  11.     int index = 0;
  12.     int betweenQuotes = 0;
  13.     char name[10];
  14.     while(unformated[n] != '\0'){
  15.         if(unformated[n] == '\"')
  16.         {
  17.             if(betweenQuotes == 0){
  18.                 betweenQuotes = 1;
  19.             }else{
  20.                 betweenQuotes = 0;
  21.             }
  22.         }else{
  23.             if(betweenQuotes == 1){
  24.                 name[index] = unformated[n];               
  25.                 index++;
  26.             }else{
  27.                 name[index] = '\0';
  28.                 std::string str(name);
  29.                 names->push_back(str);
  30.                 index = 0;
  31.             }
  32.         }
  33.         n++;
  34.     }
  35.     names->push_back("ALONSO");
  36. }
  37.  
  38.  
  39.  
  40. int main(){
  41.     FILE* f = fopen( "p022_names.txt","r+" );
  42.     char buff[BUFFER_SIZE];
  43.     std::list<std::string> names;
  44.    
  45.     char letters[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
  46.    
  47.     char* arq = fgets(buff, BUFFER_SIZE, f);
  48.    
  49.     getFirstNames(arq, &names);
  50.    
  51.     cout<<"size = "<<names.size()<<endl;
  52.    
  53.     names.sort();
  54.    
  55.     std::list<std::string>::iterator it;
  56.    
  57.     for(it = names.begin(); it != names.end(); ++it){
  58.         cout<<*it<<endl;       
  59.     }
  60.    
  61.     system("pause>null");
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement