#include <iostream>
#include <cstdlib>
#include <cstring>
usingnamespace std;
char **String = 0;
int main()
{
int row, column;
cout << "How many words will you enter? ";
cin >> row;
String = newchar *[row];
int i, j;
for (i=0; i < row; i++)
String[i] = newchar [column];
for (i = 0; i < row; i++)
{
cout << "Enter word " << i+1 << ": ";
for (j = 0; j < 25 ; j++)
cin >> String[i][j];
}
cout << "Reverse: ";
for (i = row-1; i > -1; i--)
{
cout << String[i] << endl;
}
}
my biggest issue right now is that the individual words that I'm inputting aren't correctly being dynamically assigned - each word has to be at least 25 characters before I can get "enter word #2" to show up. Any tips on what I'm doing wrong?
#include<iostream>// only header required here
usingnamespace std;
int main()
{
int row, column = 25;// column was not initialized
cout << "How many words will you enter? ";
cin >> row;
char **String = 0;// no need to be global variable
String = newchar *[row];
int i;
for (i=0; i < row; i++)
String[i] = newchar [column];// 25 characters per word. Do not exceed 24 + one for null terminator)
for (i = 0; i < row; i++)
{
cout << "Enter word " << i+1 << ": ";
cin >> String[i];// no need to cin 1 character at a time
}
cout << "Reverse: " << endl;
for (i = row-1; i > -1; i--)
{
cout << String[i] << endl;
}
// release dynamically allocated memory
for (i=0; i < row; i++)
delete [] String[i];// each array of characters
delete [] String;// the array of pointers
return 0;// return type is integer
}