cout <<"Enter a sentence :"<<endl;
cin.getline(sentence,SIZE);
cout <<sentence;
getch();
return 0;
}
This is the simple coding that let us enter a sentence in a 100 element size of array variable.Is there anyway that let us enter the sentence without specified the size ?Hence we could enter the sentence without the limitation of 100,is it related to the pointer ?
#include <iostream>
int main()
{
//Create a user input size
int size;
std::cout << "Enter Size Of Array : ";
std::cin >> size;
//Create the array with the size the user input
int *myArray = newint[size];
//Populate the array with whatever you like..
for(int i = 0; i < size; ++i)
{
myArray[i] = rand() % 10;
}
//Display whats in the array...
for(int i = 0; i < size; ++i)
{
std::cout << "Item In Element " << i << " of the array = : " << myArray[i] << std::endl;
}
//Delete the array
delete[] myArray;
return 0;
}
Manipulate something like this to possibly fit in how you want it.