lower and upper letters

Hello everybody,

I am beginner at c++, so I need some help and it would be very nice if you could help me.

I have a task to find out how many words (e. g. "boy") are in the text. But the problem is that some words may begin with upper letters (e. g. "Boy"). So I had an idea to transform the word in all upper letters and then compare with the word that I need to find. I use type string for reading words in the text and that's why the functions "strlwr" and "strupr" are unsuitable, because thay are intended for type char (line 26). What should I do in this situation?

Thanks in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <string>
#include <stdio.h>
#include <string.h>

using namespace std;
//------------------------------------
int Quantity (string eil);
//------------------------------------
int main ()
{
    string eil;
    ifstream is;
    ofstream os;
    is.open ("Text.txt");
    os.open ("result.txt");
    int x = Quantity(eil);
    int  k = 0;
    int i = 1;
    while (i <= x)
    {
        is >> eil;
        if ((!is.eof()) && (strlwr(eil) == strlwr("boy")))
        {
            k = k + 1;
            cout << eil;
        }
        i = i + 1;
    }
    cout << k;
    is.close();
    os.close();
    return 0;
}
//------------------------------------------
int Quantity (string eil)
{
    ifstream is;
    is.open("Text.txt");
    int k = 0;
    while (!is.eof())
    {
        is >> eil;
        if (!is.eof())
        {
            k = k + 1;
        }
    }
    is.close();
    return k;
}
Last edited on
Topic archived. No new replies allowed.