# Unhandled exception in C++ program



## altxerror (Aug 7, 2009)

i'm writing a program that requires a password so i made this script for a password login. 


```
static char* pass;

void Password();
 
int main()
{
	do
	{
		Password();
	}
	while( strcmp(pass, "test") != 0);
	cout << "test code here!"; 
}
 
void Password()
{
		char pass[20];
		cout << "Password: ";
		cout << "\n";
		cin.get(pass[20]);
 
		if (strcmp(pass, "test") == 0)
			return;
		else
		{
			cout << "\n\nError: Incorrect Password!";
			return;
		}
	}
```
but it gives me these 2 error whenever i try to type in anything for the password:

Run-Time Check Failure #2 - Stack around the variable 'pass' was corrupted.

if i hit break nothing happens, if i hit continue i get

"Unhandled exception at 0x57c7d440 (msvcr100d.dll) in Password.exe 0xC0000005: Access violation reading location 0x00000000."

can soomebuddy help me plz?


----------



## Ninjaboi (Dec 27, 2010)

Try removing 'static' from the declaration of 'pass'.
Try to comment off different part of the function and execute it, to find code line which causes this message.

If that isn't the problem, maybe looking at this thread might provide help:

Array of char - C++ Forums

If neither of those work, please give a bit more info if possible.


----------



## Crockeo (Apr 17, 2010)

It seems more complicated than what I'm doing (I'm very new), but I don't see anything like '#include <iostream> or using namespace std; anywhere.

(Btw, how do I put things in code boxes?)


----------



## niemiro (Feb 20, 2010)

Crockeo said:


> It seems more complicated than what I'm doing (I'm very new), but I don't see anything like '#include <iostream> or using namespace std; anywhere.
> 
> (Btw, how do I put things in code boxes?)


Hello!

I think it is a code snippet. It isn't his whole file, just the relevant portion, and so it doesn't include everything you might expect. Code snippets are exactly what is wanted.

Just do the following for code:


```
Code goes here[/code ]

^ Remove the space. These are CODE tags.

Richard
```


----------



## Crockeo (Apr 17, 2010)

Thank you, I'm kinda new to the whole coding scene.


----------



## Ninjaboi (Dec 27, 2010)

You can also used the 'Go Advanced' button to just press the button and the tags will be made for you.

This is just a snippet of code, and therefore copying then compiling this will not prove to be a successful build. Though it's easier for the people answering the question if the whole project is displayed, it usually isn't in the asking person's best interest to give away their whole project to the community.


----------

