Click to See Complete Forum and Search --> : characters in a row


quietcoder
June 7th, 2002, 11:45 AM
im using dev-c++
how can detect if there are (user input) x number of characters in a row, in a text file?

current partaning code

# include <fstream.h>
void main()
{
ofstream fout;
ifstream fin;
fin.open("input.txt");
fout.open("output.txt");
char narowa, narowb, singlea, singleb;
int howmanynarowa, howmanynarowb;
cout<<"What character do you want for singlea?:";
cin>>singlea;
cout<<"What character do you want for singleb?:";
cin>>singleb;
cout<<"how many in a row do you want for narowa?:";
cin>>howmanynarowa;
cout<<"how many in a row do you want for narowb?:";
cin>>howmanynarowb;
cout<<"what character do you want for narowa?:";
cin>>narowa;
cout<<"what character do you want for narowb?:";
cin>>narowb;
while (!fin.eof())
{
/*get characters keeping them in the same order as orginal file*/
/*turning the characters in a row that match the users inputs*/
/*into one character that the user inputs*/
/*then out putting to a different file*/
}
fout << flush;
fout.close();
fin.close();
}

the only way i can think of is to use a counter
i don't know but im sure theres a specific function to count characters in a row

JMS
June 7th, 2002, 01:46 PM
I have no idea what your asking.

quietcoder
June 7th, 2002, 07:59 PM
well what i ment was how many characters in a row of the same character.

starting with this text in a file

aababbbaaabbbbaaaabbbbbabbbb
user input
what character do you want for the a's?:C
what character do you want for the b's?:T
how many characters in row do you want combined for the a's?:3
how many characters in row do you want combined for the b's?:4
what character do you want for the combined a's?:F
what character do you want for the combined b's?:H

ends with this text out to a diferent file

CCTCTTTHFCHTCH

quietcoder
June 8th, 2002, 10:49 PM
what im asking is how can i detect the number of charaters in a row of the same character in a text file? is there a function or somthing that checks that?

Paul McKenzie
June 10th, 2002, 11:16 AM
Originally posted by quietcoder
well what i ment was how many characters in a row of the same character.

starting with this text in a file

aababbbaaabbbbaaaabbbbbabbbb
user input
what character do you want for the a's?:C
what character do you want for the b's?:T
how many characters in row do you want combined for the a's?:3
how many characters in row do you want combined for the b's?:4
what character do you want for the combined a's?:F
what character do you want for the combined b's?:H

ends with this text out to a diferent file

CCTCTTTHFCHTCH By your description, the output shouldn't even look like what you are describing. I can understand the first "CCTCTTT", since you are replacing the 'a' with a C and the 'b' with a T, but after that, it is almost impossible to understand what you are trying to do.

Anyway, you should read the file into a buffer. Then traverse the buffer counting characters as you go along.

There is no function that counts the number of characters in a row, unless you use C++ and maybe some algorithm functions. If that is too complex, then you have to count them using a loop and a counter that reverts back to 0 when a letter changes.

Regards,

Paul McKenzie