"Project8.exe has stopped working"

I keep on getting error messages at the end of my program, can anyone help check for errors?

#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;
int main(){

char myArray[10];

cout <<"Password required: ";

cin.getline( myArray, 10, '\n');

if( !strcmp( myArray, "Warrior")){

strcat( myArray, " is correct, Access granted!\n");{

int a;
int b;
int c;

cout <<"Insert first number:";
cin >> a;

cout <<"Insert second number:";
cin >> b;

c= a+b;

cout <<"Sum:" << c << "\n";

}

} else {

strcpy( myArray, "Password incorrect, access denied!\n");

}

cout << myArray;

system("Pause");

}
FYI, this forum support code formatting. Use code tags next time.

The problem: You are concatenating to myArray a string larger than 10 characters. You are corrupting the stack, most likely. Always use strncat() instead; same goes for strcpy() (use strncpy() instead), etc.
Thanks for helping, it's working now.

Sorry about not using the code tags, I had no idea.

Anyway, what does the extra 'n' do?
If you look up those functions (with the extra n), you'll notice that they require the destination size from you, the programmer. Assuming that you, the programmer, won't lie about the destination size, the n-versions will perform a check to see if what you want to do (concatenate, copy, etc.) can be done in the specified destination without exceeding the destination's capacity.
Topic archived. No new replies allowed.