file processing

R

Roberto Dias

Hi,

I've got a text file and I need to capture some data in it. I
implemented ( using comp.lang.c++ help) a typical searching algorithm
that first find the header (label that identifies the data inside the
text file) of the interested data, giving me a pair row-column and now
I need to jump some lines foward for getting the data. I'm so shine
about that, but I simply cannot do this last thing! I've trying,
without no success, to "getline" to a temporary file for creating a
big "char" matix and after use the pair row-column to identifies and
get the data, but this is so much complex to a simple thing.
Here are my code:

#include<iostream>

using std::cout;
using std::cin;
using std::endl;

#include<fstream>

using std::ios;
using std::ifstream;
using std::eek:fstream;

#include<string>

using std::string;

void coletaDadosSimulacaoDinamica(void);

int main()
{
// Limpeza da tela
system("cls");

coletaDadosSimulacaoDinamica();

return 0;
}

void coletaDadosSimulacaoDinamica(void)
{
string nomeArquivoStb, stringLinhaCopiada, consulta = "DSIM";
string::size_type posicao(0);
const string::size_type tamanho(consulta.size());
char arrayLinhaCopiada[255];
int contadorLinha = 0;

cout << "Entre o arquivo .stb: ";
cin >> nomeArquivoStb;
cout << endl;

ifstream objetoArquivoStb(nomeArquivoStb.c_str());

while (objetoArquivoStb.getline(arrayLinhaCopiada, 255))
{
stringLinhaCopiada = arrayLinhaCopiada;

if (stringLinhaCopiada.find(consulta) != string::npos)
{

while((posicao = stringLinhaCopiada.find(consulta, posicao)) !=
string::npos)
{
// Imprime na tela o numero da linha da ocorrencia
cout << "Substring encontrado na linha " << (contadorLinha +
1);
cout << ", coluna " << (posicao + 1) << endl;
cout << endl;

// Incremento da posicao
posicao += tamanho;
}
}

//objetoArquivoAux << stringLinhaCopiada;

// Contador de linhas
contadorLinha++;
}
}

Unfortunately the comments are in Portuguese language.

Can we change some ideas?

Thanks a lot,

Roberto Dias
 
D

David Harmon

On 27 Jun 2004 16:04:02 -0700 in comp.lang.c++, (e-mail address removed)
(Roberto Dias) wrote,
ifstream objetoArquivoStb(nomeArquivoStb.c_str());

while (objetoArquivoStb.getline(arrayLinhaCopiada, 255))
{
stringLinhaCopiada = arrayLinhaCopiada;

if (stringLinhaCopiada.find(consulta) != string::npos)
{

// add:
posicao = 0;
while((posicao = stringLinhaCopiada.find(consulta, posicao)) !=
string::npos)

For the first line from the file, posicao is 0 and all is good.
For the remaining lines, posicao is stuck at npos and find() will fail.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top