Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<list>
- #include <cctype>
- #define BUFFER_SIZE 46448
- using namespace std;
- void getFirstNames(char* unformated, std::list<std::string>* names){
- int n = 0;
- int index = 0;
- int betweenQuotes = 0;
- char name[10];
- while(unformated[n] != '\0'){
- if(unformated[n] == '\"')
- {
- if(betweenQuotes == 0){
- betweenQuotes = 1;
- }else{
- betweenQuotes = 0;
- }
- }else{
- if(betweenQuotes == 1){
- name[index] = unformated[n];
- index++;
- }else{
- name[index] = '\0';
- std::string str(name);
- names->push_back(str);
- index = 0;
- }
- }
- n++;
- }
- names->push_back("ALONSO");
- }
- int main(){
- FILE* f = fopen( "p022_names.txt","r+" );
- char buff[BUFFER_SIZE];
- std::list<std::string> names;
- 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'};
- char* arq = fgets(buff, BUFFER_SIZE, f);
- getFirstNames(arq, &names);
- cout<<"size = "<<names.size()<<endl;
- names.sort();
- std::list<std::string>::iterator it;
- for(it = names.begin(); it != names.end(); ++it){
- cout<<*it<<endl;
- }
- system("pause>null");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement