Hello. Had an assignment using dynamic array allocation. Instructions: Write a program that prompts the user to input the length of a string as an integer, followed by the string and outputs the string in uppercase letters using dynamic arrays.
Not really sure how to use dynamic array allocaiton. Heres my code (sorry for bad english, from chile):
Have you considered searching the web for "dynamic array allocation" and seeing the links to tutorials that show up?
The basic setup is:
1 2 3 4 5 6 7 8 9 10 11
int length;
cin >> length; // input from user
char* str = newchar[length+1]; // allocate
str[length] = '\0'; // null terminate just in case (probably redundant but I don't feel like looking up documentation right now. I'm tired.)
cin.get(str, length); // get the actual string from user input
cout << str << '\n'; // further processing... e.g. display it
delete[] str; // clean up memory (don't leak memory!)