I have to redo Programming Exercise 5 of Chapter 9 using dynamic arrays. I have the problem but I don't know how to use it using dynamic arrays please help.

//Chapter 9: Programming Exercise 5

#include <iostream>
#include <cstring>
#include <cctype>
  
using namespace std;

int main()
{
    char str[81];

    int len;

    int i;

    cout << "Enter a string: ";
    cin.get(str, 80);
    cout << endl;
    cout << "String in upper case letters is:" << endl;

    len = strlen(str);
    for (i = 0; i < len; i++)
        cout << static_cast<char>(toupper(str[i]));
    cout << endl;

    return 0;
}

For dynamic arrays first forget anything about uppercasing for the moment and read about the new and delete keywords. This is how C++ dynamically allocates memory. So after you're familiar with this read an (unsigned) integer via cin . Use new to allocate the array of the size the integer specifies. cin.get() that array. Then use toupper() . Then delete[] the array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.