After some criticism regarding this post I have decided to try another solution to test my issue.
I purpose of the code below was to save user input into an array and then output it when user types in exit
. I am relatively new to C++ which means that I am aware that this is a code issue.
The constraints for this code are to not use STL or strings.
I have attached the code below which does not give the desired output, instead it prints out "exit" the number of times equal to the number of items stored in the array.
#include <iostream>
char * textArr[1000];
int lineCount = 0;
void saveText(char * text) {
textArr[lineCount] = new char(1000);
strcpy(textArr[lineCount], text);
}
int main()
{
char * line = new char(1000);
while (lineCount < 1000) {
std::cin.getline(line , 1000);
if (strcmp(line, "exit") == 0) {
break;
}
saveText(line);
lineCount++;
}
for (int i = 0; i < lineCount; i++) {
std::cout << textArr[i] << std::endl;
}
delete(textArr);
delete(line);
return 0;
}