I'm playing with all the cstring and string functions, getting familliar with how they work. Below I have a function call to strcata, and all I'm doing is declaring a string within the function, I'm not even using it with anything other than cout. Everytime I run the code it crashes, can anyone tell me why the following code crashing?
/*
Practice for cstring parsing
*/
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
// ****** Prototypes *********************************************
// void strcpy();
// void strncpy();
// void strcat(char []);
void strcata();
// ****** MAIN ***************************************************
int main()
{
// string example3 = "This is example 3";
// strcpy();
// strncpy();
// strcat(example3.c_str());
strcata();
return 0;
}
// ****** FUNCTION: strcat ***************************************
// char* strcat(char* destination, const char* source);
//
// Appends the source to the end of the destination
// ***************************************************************
void strcata()
{
char buffer[80] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
char example1[] = "This is example 1";
char example2[] = "This is example 2";
string example3 = "This is example 3";
cout << example3 << endl;
// strcat(example1, example3);
strcat(example1, example2);
cout << example1 << endl;
cout << strlen(example1) << endl;
cout << strlen(example2) << endl;
strcat(buffer, example1);
cout << buffer << endl;
cout << strlen(buffer) << endl;
cout << strlen(example1) << endl;
}