Quick look at "Accepts a pointer to a C-String" What does this mean???

I have made this program run, however in the book it says my functions should "accept a pointer to a c-string as its argument." Please help me if you can.

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

void vowCounter(string);
void conCounter(string);

int main()
{
	//Definition of str, as well as the menu display
	string str;
	char choice;
	
	do
	{	
		cout << endl;
		cout << "Enter a string: ";
		cin >> str;

		cout << endl;
		cout << "What do you wish to do in the string? " << endl;
		cout << "A) Count the number of vowels" << endl;
		cout << "B) Count the number of consonants" << endl;
		cout << "C) Count both the vowels and consonants" << endl;
		cout << "D) Enter another string instead" << endl;
		cout << "E) Exit the program" << endl;
		cin >> choice;

	
		{
			switch (toupper(choice))
			{
			case 'A':
			{
				vowCounter(str);
				cout << endl;
				break;
			}
			case 'B':
			{
				conCounter(str);
				cout << endl;
				break;
			}
			case 'C':
			{
				vowCounter(str);
				cout << endl;
				conCounter(str);
				cout << endl;
				break;
			}
			case 'D':
			{
				continue;
				break;
			}
			case 'E':
			{
				cout << "Exiting the program....." << endl;
				break;
			}
			default:
			{
				cout << "Input is invalid, try again. ";
				cout << endl;
				break;
			}
				}
			}
	} while (toupper(choice) != 'E');

	return 0;
}

void vowCounter(string str)
{
	char temp;
	int vowelC = 0;

	for (int i = 0; i < str.size(); i++)
	{
		temp = toupper(str[i]);
		switch (temp)
		{
		case 'A':
		case 'E':
		case 'I':
		case 'O':
		case 'U':
			vowelC++;
			break;
		default:
			break;
		}
	}
	cout << "There are " << vowelC << " vowels in the string." << endl;
}

void conCounter(string str)
{
	char temp;
	int consonC = 0;

	for (int i = 0; i < str.size(); i++)
	{
		temp = toupper(str[i]);
		switch (temp)
		{
		case 'A':
		case 'E':
		case 'I':
		case 'O':
		case 'U':
			break;
		default:
			consonC++;
			break;
		}
	}
	cout << "There are " << consonC << " consonants in the string." << endl;
}
What is the title and author of your book?
starting out with C++ from control structures through objects, by tony gaddis
I would be hesitant about any book claiming to teach C++ that requires you to use c-style strings. I would recommend just using std::string as you have already done.
Thought so, thank you for helping. Also, LB would you care to run my program, and help me fix the problem where, if you enter a string with spaces it does not compile right.
You could replace line 20 with std::getline(std::cin, str); to read an entire line of input instead of just the first word.
Thank you, I thought I had that, guess I overlooked it lol
Topic archived. No new replies allowed.