compiling error 17: error: expected initializer before 'void'

I've been trying to get rid of this error for the past couple of hours, if anyone could help me get rid of it that would be great. Thanks!
When trying to compile it returns
compiling error 17: error: expected initializer before 'void'


Last edited on
Very hard to read without code tags...however, you are declaring functions inside of main. You should move your functions outside the scope of main.
Last edited on
i moved my functions outside of my main function, and now im getting not only the same error, but another error in addition to it.
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
using namespace std;


void WordCountInLine(string line, int& WordCount)
void NumberOfBlanks(string line, int& NumofBlanks, int& NonnumBlank)

void WordCountInLine(string line, WordCount);
// This function counts the words in a line of text.
{
	
	string delimiters = " .,?:;!()";
	int charCount;
	char currentChar;
	
	//  Add delimiter at the end of the line for word identification.
	line = line + '?';
	//  Initialize word count as zero.
	WordCount = 0;
	//  Initialize a flag that indicates we start without being in a word.
	bool InsideWord = false;
	//  For each character in line
	for ( charCount = 0; charCount<line.length(); charCount++ )
	{
		//  Set current chatacter
		currentChar = line.at(charCount);
		//  If it is not a delimiter
		if ( delimiters.find( currentChar ) == string::npos )
		{
			//  If in a word
			if (InsideWord)
				//  Increment current word length
				WordCount++;
			//  else (not in a word)
			else
			{
				//  Starting a word - Change in word flag 
				InsideWord = true;
				//  Start keeping word count.
				WordCount = 1;
	 		}
 		}	
		// else character is a delimiter	
		else
		{
			// If in a word.
			if (InsideWord)
			{
				// You're reaching the end of the word. (marked by delimiter) reset flag for inword
				InsideWord = false;
				// else not in a word.
		
				// Do nothing, the computer is in between words.
			}
		}
	}	
}

void NumberOfBlanks(string line, NumofBlanks, NonnumBlank);
// This function will count the number of blanks and the number 
// of non-blank characters in a string of text.
{
	//Initialize blanks and non blanks to zero.
		NumBlanks = 0;
		NonBlank = 0;
	// For each character in line
	for ( charCount=0; charCount<line.length(); charCount++ )
	{
		// Set current character
		currentChar = line.at(charCount);
		// If current character is a blank
		if (currentChar == ' '); 
		{
			NumBlanks = NumBlanks + 1;
		}
		//else current character is a non blank character.
		else
		{
			NonBlank = NonBlank + 1;
		}
	}
}
int main()
{

7: error: expected initializer before 'void'
19: error: expected unqualified-id before '{' token
Last edited on
There are no semicolons for your prototypes, but you don't need prototypes since your functions are declared before main starts anyways so just remove the first two lines after using namespace std;
Last edited on
Ah, alright thanks :) Somehow I got it to compile, thanks!
And remove the semicolon, here void WordCountInLine(string line, WordCount); at the start of the function.
For those reading this later, the code above should begin

1
2
3
4
5
6
7
8
9
10
using namespace std;


void WordCountInLine(string line, int& WordCount); // ; was missing
void NumberOfBlanks(string line, int& NumofBlanks, int& NonnumBlank); // ; was missing

void WordCountInLine(string line, int& WordCount) // int& was missing, ; was unwanted
// This function counts the words in a line of text.
{
     ...


The error on line 7 was due to the missing ; on the previous statement.
The error on line 19 was because the ref param was incompletely declared (no type)
Don't forget this line down below:

Before:
void NumberOfBlanks(string line, NumofBlanks, NonnumBlank);

After:
void NumberOfBlanks(string line, int& NumofBlanks, int& NonnumBlank)
Topic archived. No new replies allowed.