Check string in a file and create email without "Junior, grandson and child"

0

I need to check within the list below:

NAME, REGISTRATION FELIPE OLIVEIRA DE JESUS, 71 HENRIQUE HIROMI SHIMADA, 67 ISAAC DE OLIVEIRA PIRES, 52 JONES SABINO SILVA, 4 LUCAS PEREIRA CORREA DE SOUZA, 42 MARCOS HENRIQUE RIOS PEREIRA, 58 MARCOS PAULO DE BRITO ANDRADE, 36 MURILO VICENTE DA SILVA, 92 NILDOARDO ROQUE DA SILVA JUNIOR, 89 PEDRO LAURO NUNES DUARTE NETO, 38 RODRIGO BRESSAN DE SOUZA FILHO, 34 THIERRY ALVES REIS OLIVEIRA, 95 VICTOR HIROSHI CASTRO KAWAMOTO, 3 VICTOR SEIJI UEMA, 35

and create an email with the rules first name.last name.matrí[email protected]

NETO, SON, JUNIOR can not be used as a last name. In this case, use the penultimate name.

My code is talking when it is to identify the JUNIOR, NETO AND SON is returning the full name as email example Jose Silva Santos Junior, 10 Inves to return [email protected] is returning jose.silva [email protected]

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <string>

using namespace std;

void outputLine(const string); // protótipo
string changeStr( const string );

int main()
{

    int iCntLn = 0;

    // construtor ifstream abre o arquivo
    ifstream inAlunosFile("Aula_10_Arquivos_em_C++_saida.txt", ios::in);

    // fecha o programa se ifstream não pôde abrir o arquivo
    if (!inAlunosFile)
    {
        cerr << "O arquivo não pode ser aberto" << endl;
        exit(1);
    }

    char fullname[30];
    char matricula[2];
    string line;
    string chgline;

    cout << left << "E-Mail Instituciuonal" << endl;

    // exibe cada registro no arquivo
    while (!inAlunosFile.eof())

          if( iCntLn == 1 )
              {
                     getline(inAlunosFile,line);
                     chgline = changeStr(line);
                     outputLine(chgline);
              }
          else
              {
                     getline(inAlunosFile,line);
                     chgline = changeStr(line);
                     iCntLn++;
              }


    system("pause");
    return 0;
}

string changeStr( const string line)
{
       int namePos = line.find(" ");
       string name = line.substr(0,namePos);

       int commaPos = line.find(",");
       int lastnamePos = line.rfind(" ");
       string lastname = line.substr(lastnamePos+1,commaPos-lastnamePos-1);

       if( lastname == "NETO" || lastname == "FILHO" || lastname =="JUNIOR" )
       {
           int newlastnamePos = line.rfind(" ");
           lastname = line.substr(namePos+1,newlastnamePos-namePos-2);
       }

       string matricula = line.substr(commaPos+1,2);

       return name + "." + lastname + "." + matricula;
}
// exibe um registro do arquivo
void outputLine(const string sline)
{
    cout << left << sline + "@ifsp.edu.br"<< endl;
}
    
asked by anonymous 07.10.2018 / 23:55

0 answers