Debug Assertion Error.

I keep getting this weird error message, and i don't even understand what it's about or where my problem is.

http://s23.postimg.org/52b4xgva3/error.png
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
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;

//bool ofCheck(int);
void sentenceAnalysis(char*, int, int,int &);
bool theCheck(int, char*);
void main()
{
	char paragraph[1000];
	int ofTotal = 0, sentenceNum = 0, theTotal=0, wordTotal=0;
	cout << "Enter a paragraph here: ";
	cin.getline(paragraph,1000);
	int size = strlen(paragraph);
	char* pgraph;
	pgraph = new char[size];
	pgraph = paragraph;
	
	for (int count = 0; count < strlen(pgraph); count++)
	{
		if (pgraph[count] == '.' || pgraph[count] == '!' || pgraph[count] == '?' || pgraph[count] == ':')
		{
			sentenceNum++;
			sentenceAnalysis(pgraph, count, sentenceNum, theTotal);
		}
		else if (pgraph[count] == ' '&& pgraph[count - 1] != ' ')
			wordTotal++;
	}
	cout
		<< " the word 'the' appeared" << theTotal << " time(s). " << endl
		<< " percentage of 'the' over all the words is" << theTotal / wordTotal << '%' << endl
		<< " the average amount of words per sentence " << wordTotal / sentenceNum << endl;
 
	system("pause");

}

void sentenceAnalysis(char* pgraph, int count, int sentenceNum,int &theTotal)
{
	int wordCount = 0, count2 = 0,  theCount=0; 
	for (int count2 = 0; count2 < count; count2++)
	{
		if (pgraph[count2] == ' '&& pgraph[count2-1] != ' ')
			wordCount++;
		else if (tolower(pgraph[count2]) == 't' )
		{
			if (theCheck(count2, pgraph))
			{
				theCount++;
				theTotal++;
			}
			
		}
		
		
	}
	cout << "Sentence" << sentenceNum << ": Contains " << wordCount << " words and contains the word 'the' " << theCount << "times"<<endl;

	theCount = 0;

}

bool theCheck(int count2, char* pgraph)
{	

	if (tolower(pgraph[count2]) == 't' && tolower(pgraph[count2 + 1]) == 'h' && tolower(pgraph[count2 + 2]) == 'e'
		&&  isalpha(pgraph[count2 - 1]) == false && count2-1 > 0 && isalpha(pgraph[count2+3])==false)
		
	{
		return true;
	}
	else
	{
		return false;
	}

}.
Line 31-33. You are dividing some value by 0
Last edited on
this assertion is a problem of the ctype functions (tolower, isalpha, etc). If you have a char outside the basic ascii range (0 - 128)

Try using the locale equivalents:

http://www.cplusplus.com/reference/locale/isalpha/
http://www.cplusplus.com/reference/locale/
Topic archived. No new replies allowed.