Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * (C) 2011 Angelo S. Mavridis Bartolome <barklome@gmail.com>
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
- /*
- Tutoral Qt : Contador de palavras
- Escrito por: Angelo S. Mavridis Bartolome
- Livre para copiar, só não pode falar que você quem fez :)
- */
- #include <QDebug>
- #include <QFile>
- int main(int argc, char *argv[])
- {
- QFile f(argv[1]); // Cria instancia do QFile
- int contar = 0; // Cria um contador
- if(argc < 3)
- {
- qDebug() << "Uso: ./aplicativo ARQUIVO PALAVRA";
- return 1; // Retorna 1: Falha. Retorna 0: Sucesso
- }
- if(!f.open(QIODevice::ReadOnly | QIODevice::Text))
- {
- qDebug() << "Falha ao abrir o arquivo: " << f.fileName();
- return 1; // Retorna falha novamente
- }
- QTextStream arquivoTexto(&f);
- QString linha;
- while(!arquivoTexto.atEnd())
- {
- linha = arquivoTexto.readLine();
- contar = contar + linha.count(QString(argv[2]));
- }
- qDebug() << "Lido: " << f.fileName() << ". Contado " << contar << argv[2] << "(s)";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement