Sponsored Content
Homework and Emergencies Homework & Coursework Questions C++ homework, finding a letter from a file Post 302591139 by solaris_user on Wednesday 18th of January 2012 03:47:25 PM
Old 01-18-2012
C++ homework, finding a letter from a file

Write a program which asks user to enter a string and that string saves in a .txt file. After the file has been saved your program must count how many time letter 'a' has been reapeated ?

Use fstream, string, and cctype libraries to make your jobe easier.

I wrote following code
Code:
#include <iostream>
#include <fstream>
#include <cctype>
#include <string>
#include <cstdlib>

using namespace std;

int main(void)
{
    string input, exit;
    int let_a = 0;;
    fstream text("test.txt", ios::in | ios::out | ios::app );

    cout << "Enter string: ";
    cin  >> input;

    if (!text)
    {
        cout << "Error at stream opening" << endl;
        system("PAUSE");
        exit(EXIT_FAILURE);
    }

    text << input;

    while ( !text.eof() )
    {
        while ( getline(text, exit) )
                {
                    for (int i = 0; i < exit.length(); i++)
                    {
                            if ( toupper(exit[i]) == 'A')
                            {
                                let_a++;
                            }
                    }
                }
        }
     text.close();

    cout << "total A: " << let_a << endl;

    system("PAUSE");
    return 0;
}

I googled and also asked my friends but nobody can find an error Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to find capital letter names in a file without finding words at start of sentence

Hi, I want to be able to list all the names in a file which begin with a capital letter, but I don't want it to list words that begin a new sentence. Is there any way round this? Thanks for your help. (1 Reply)
Discussion started by: kev269
1 Replies

2. UNIX for Dummies Questions & Answers

i need 100th occurance of a letter in file

Hi to all, I am looking a file in vi editor to get 100th occurance of a latter in that file. Can any one help me in this? Thanks Sathish (1 Reply)
Discussion started by: bsathishmca
1 Replies

3. Shell Programming and Scripting

Shell - Matching 3 letter file names

Hi I am running a shell script with bdf command and want to match all files with length 3 inside a specific partitions. How do i do that say for example if i want to list all files with length 3 in /home/jimmy partition, bdf /home/jimmy the output i need is xyx abc yyy amp ... (4 Replies)
Discussion started by: PrasannaKS
4 Replies

4. Shell Programming and Scripting

Finding a letter in a string

How to check whether a particular string contains dot or not? Here I can not use grep as the string is not in a file. I will get this string from user input Thanks, (2 Replies)
Discussion started by: balamv
2 Replies

5. UNIX for Dummies Questions & Answers

Display File with a specific letter

Hi im a noob in Unix Do you guys know what command display you the files that have the character n in there name im not looking that they have the n in the beginning or in the end im looking that in search the entire string to see if it have the character n i try this ls n* but only show... (2 Replies)
Discussion started by: Kaziduz
2 Replies

6. Shell Programming and Scripting

Get all File names starting with letter P

Hi, I have lets say 10 files , I need to process them one by one. So I need a command to get one file name at a time to process it into a variable Example Files P1111.dat P3344.dat S344.dat ... v_file_name = 'p111.dat' .. I will rename it to something after processing ... (1 Reply)
Discussion started by: prassu
1 Replies

7. Shell Programming and Scripting

check index of a string by finding a letter in it

i would like to search for a letter in a string and get its index position. example: name='john' pos=$(expr index $name o) the result will be equal to 2 (2nd position) how do you make this thing not case sensitive? example: name='john' pos=$(expr index $name O) the... (1 Reply)
Discussion started by: kokoro
1 Replies

8. Shell Programming and Scripting

Getting the non-homogenous letter row from a text file

I do have a large tab delimited file with the following format CCCCCGCCCCCCCCCCcCCCCCCCCCCCCCCCC 23 65 3 4 AAAAAAAAAAAAAAAAaAAAAAAAAAAAAAAAA 24 6 89 90 TGTTTTTTTTTTTTGGtTTTTTTTTTTTTTTTT 2 4 8 90 TTTT-TTTTTTTTTTTtTTTTTTTTTTTTTTTT 1 34 89 50 GGGGGGGGGGGGGGGGTGGGGGGGGGGGGGGGG 87 6 78 66... (8 Replies)
Discussion started by: Lucky Ali
8 Replies

9. Shell Programming and Scripting

Multiplying lines of file that contain certain letter by value

I am trying to remove the last letter in a file and then multiply each line (which contained this letter) by 500. This is what I have: 1499998A 1222222A 1325804A 1254556 1235 9998 777 cat /tmp/listzz |gawk '{print $4}'|gawk '{gsub(//, ""); print } This removes the A... (1 Reply)
Discussion started by: newbie2010
1 Replies

10. Shell Programming and Scripting

Replace specific letter in a file by other letter

Good afternoon all, I want to ask how to change some letter in my file with other letter in spesific line eg. data.txt 1 1 1 0 0 0 0 for example i want to change the 4th line with character 1. How could I do it by SED or AWK. I have tried to run this code but actually did not... (3 Replies)
Discussion started by: weslyarfan
3 Replies
FBB::IOStreambuf(3bobcat)					   Error handler					 FBB::IOStreambuf(3bobcat)

NAME
FBB::IOStreambuf - streambuf allowing input and output operations SYNOPSIS
#include <bobcat/iostreambuf> Linking option: -lbobcat DESCRIPTION
This class implements a specialization of the std::streambuf class, allowing input operations from and output operations to different files. It is intended to be used in combination with FBB::IOStream, thus allowing all stream-based input and output operations using the same object without the need to use seek-operations. Using an FBB::IOStream object it is, e.g., possible to construct two-way communica- tions using pipes, much like the facilities offered by sockets. If the streams that will be associated with the IOStreambuf object support seeking, then the IOStreambuf will do so to. Seeking might also be availble for a single stream (either the std::istream or the std::ostream). When the IOStreambuf object goes out of scope, its associated std::ostream object is flushed. NAMESPACE
FBB All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB. INHERITS FROM
std::streambuf CONSTRUCTORS
o IOStreambuf(): The default constructor results in a IOStreambuf object that cannot be immediately used. Its member open() must be called first. o IOStreambuf(std::istream &in, std::ostream &out): This constructor associates the IOStreambuf object with a std::istream and a std::ostream. All output operations will be passed on to the std::ostream, all input operations to the std::istream. The streams passed to IOStreambuf() should outlive the IOStreambuf object. De copy constructor is available as well. MEMBER FUNCTIONS
All members of std::streambuf are available, as FBB::IOStreambuf inherits from these classes. o void open(std::istream &in, std::ostream &out): This member (re)associates the IOStreambuf object with a std::istream and a std::ostream. All output operations will be passed on to the std::ostream, all input operations to the std::istream. The streams passed to IOStreambuf() should outlive the IOStreambuf object. If this member is called for an IOStreambuf object already associated with an std::ostream object, the already associated std::ostream object is flushed before setting up the new association. VIRTUAL PROTECTED MEMBER FUNCTIONS
The following std::streambuf member functions should only be called when the FBB::Streambuf object is associated with std::istream and std::ostream objects (i.e., they should not be called between the construction of a default FBB:IOStreambuf object and a subsequent call of IOStreambuf::open()): The members listed in this section implement the tasks of comparably named virtual function in the class's private interface. This sepa- rates the redefinable interface from the user-interface. The class IOStreamBuf can, in accordance with Liskov's Substitution Principle, be used as a std:streambuf; but it also offers facilities for classes deriving from IOStreamBuf. These facilities are listed here. o pos_type pSeekoff(off_type offset, std::ios::seekdir way, std::ios::openmode mode = std::ios::in | std::ios::out): With seekable streams, repositions the associated std::istream or std::ostream is repositioned to offset offset, relative to way. o pos_type pSeekpos(off_type offset, std::ios::openmode mode = std::ios::in | std::ios::out): With seekable streams, repositions the associated std::istream or std::ostream is repositioned to offset offset, relative to the beginning of the stream. o int pSync(): This member flushes the associated std::ostream object. o std::streamsize pXsputn(char const *buffer, std::streamsize n): This member inserts n characters from buffer into the associated std::ostream stream. EXAMPLE
See the example provided with process(3bobcat). FILES
bobcat/iostreambuf - defines the class interface SEE ALSO
bobcat(7), iostream(3bobcat), process(3bobcat) BUGS
None reported. DISTRIBUTION FILES
o bobcat_3.01.00-x.dsc: detached signature; o bobcat_3.01.00-x.tar.gz: source archive; o bobcat_3.01.00-x_i386.changes: change log; o libbobcat1_3.01.00-x_*.deb: debian package holding the libraries; o libbobcat1-dev_3.01.00-x_*.deb: debian package holding the libraries, headers and manual pages; o http://sourceforge.net/projects/bobcat: public archive location; BOBCAT
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'. COPYRIGHT
This is free software, distributed under the terms of the GNU General Public License (GPL). AUTHOR
Frank B. Brokken (f.b.brokken@rug.nl). libbobcat1-dev_3.01.00-x.tar.gz 2005-2012 FBB::IOStreambuf(3bobcat)
All times are GMT -4. The time now is 04:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy