CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2002
    Posts
    16

    Question characters in a row

    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
    logical coding for functional programs

  2. #2
    Join Date
    May 2000
    Location
    Washington DC, USA
    Posts
    715
    I have no idea what your asking.

  3. #3
    Join Date
    Jun 2002
    Posts
    16
    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
    logical coding for functional programs

  4. #4
    Join Date
    Jun 2002
    Posts
    16
    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?
    logical coding for functional programs

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured