The original code where this error occurred is a tool I made in an online C++ compiler but I've simplified the code so its easier to understand
What this code is supposed to do is you input an integer indicating the amount of sentences you want to connect. Then you enter each sentence and when you entered the amount of sentences you specified then you get the all the sentences in a single string and end the program with an exit code of 0. However when you increase the size of the stringInput array(by changing the InputSize definition to something like 600) the result you get at the end is a bunch of wrong characters and symbols that have nothing to do with what you inputted:
#include <iostream>
#include <bits/stdc++.h>
#include <string>
using namespace std;
string convertToString(char* a, int size) //character array to string function
{
int i;
string s = "";
for (i = 0; i < size; i++) {
s = s + a[i];
}
return s;
}
#define InputSize 300 // This is the value that bugs out whenever its larger than 400 sometimes when its on 350 it randomly works or bugs out
int main()
{
int AmountOfStrings = 1;
char StringInput[InputSize];
char CleanChar;
string FinalString = "";
cout<<"amount of connected sentences:";
cin>> AmountOfStrings;
for (int i=-1; i < AmountOfStrings; i++){
if (i != -1){
cout<<"sentence n";
cout<<i + 1;
cout<<":\n";
}
cin.getline(StringInput,InputSize); // get the character array of what the user inputs
FinalString = FinalString + convertToString(StringInput,InputSize); //convert the char array to string and connect the final string to the inputed sentence
for(int i = 0;i < InputSize;i++){
StringInput[i] = CleanChar;
}// this loop is to iterate trough all StringInput characters and set them to nothing
}
cout<<FinalString;
return 0;
}