Debug assertion failed! Invalid null pointer.

I got a school assignment where I need to encrypt what the user writes in and then decrypt it againt. I can run this code so it starts but when I come to the point where I write in the text that should be encrypted I get a window pooping up saying:
"Debug Assertion Failed!

Program:...cts\Programmering Projekt C\Debug\Programmering Projekt C.exe
File:c:\program files (x86)\microsoft visual studio 10.0\vc\include\xstring
Line:929

Expression: invalid null pointer

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

(Press Retry to debugg the application)"

I can't find anything on how to fix this or what is creating this error, I would really appreciate some help with this.

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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  #include <iostream>
#include <string>	
#include <iomanip>	
#include <istream>
using namespace std;

int val, storlek, rot, start, längd;
char x;
double samtalspris(), momsfunktion();
double telefonsumma, Totaltelefonsumma, sluttid, helminuter2;												
double rabattsumma, telefonsumma1, pris, helminuter1, starttid,  totalminuter;
string delsträng, timmar1, minuter1, timmar2, minuter2, kryptering(), dekryptering(), text;													
double rabatt = 0.15;																		
double kostnad = 3;																				
double moms = 1.25;	

int main()
{
switch (val)
{	
	case 1:	
		cout<<"Skrev in texten du vill ha krypterad: ";
			getline(cin, text);
		cout<<endl;
		cout<<"Din text krypterad är: ";
		cout<<kryptering();
		cout<<endl;
			text=kryptering();
		cout<<"Din text dekrypterad är: ";
		cout<<dekryptering();
		cout<<endl;
		main();
		break;
}
string kryptering()																				
{
	for( int i=0; i<text.size(); i++)
	{
		if(i%5==0)
		{
			 x*=-1;
		}
		if (x==-1)
		{
			if (text[i]>='a'&&text[i]<='m')
			{
				text[i]-=7;
			}
			else if (text[i]>='m'&&text[i]<'z')
			{
				text[i]+=7;
			}
			else if (text[i]>='A'&&text[i]<='M')
			{
				text[i]-=7;
			}
			else if (text[i]>='M'&&text[i]<='Z')
			{
				text[i]+=7;
			}
		}
		else (x==1);
		{
			if (text[i]>='a'&&text[i]<='m')
			{
				text[i]-=13;
			}
			else if (text[i]>='m'&&text[i]<='z')
			{
				text[i]+=13;
			}
			else if(text[i]>='A'&&text[i]<='m')
			{
				text[i]-=13;
			}
			else if(text[i]>='M'&&text[i]<='m')
			{
				text[i]+=13;
			}

		}

	}
	return 0;																				
}																								

string dekryptering()
{

	for( int i=0; i<text.size(); i++)
	{
		if(i%5==0)
		{
			 x*=-1;
		}
		if (x==-1)
		{
			if (text[i]>='a'&&text[i]<='m')
			{
				text[i]+=7;
			}
			else if (text[i]>='m'&&text[i]<'z')
			{
				text[i]-=7;
			}
			else if (text[i]>='A'&&text[i]<='M')
			{
				text[i]+=7;
			}
			else if (text[i]>='M'&&text[i]<='Z')
			{
				text[i]-=7;
			}
		}
		else (x==1);
		{
			if (text[i]>='a'&&text[i]<='m')
			{
				text[i]+=13;
			}
			else if (text[i]>='m'&&text[i]<='z')
			{
				text[i]-=13;
			}
			else if(text[i]>='A'&&text[i]<='m')
			{
				text[i]+=13;
			}
			else if(text[i]>='M'&&text[i]<='m')
			{
				text[i]-=13;
			}

		}

	}
	return 0;							
}				
																			

A lot is wrong here really, but one big problem (lines 84 and 137) is that you're returning a 0 instead of a string.
Topic archived. No new replies allowed.