Write a program to allocate memory dynamically for a sentence to enter by user, ask user to know the no of character in his/her sentence

 /*Write a program to allocate memory dynamically for a sentence to enter by user, ask user to know the no of character in his/her sentence*/

#include<iostream>

#include<iomanip>

using namespace std;

int main(){

int n;

cout<<"How many character there are in your sentence?";

cin>>n;

char *cp= new char[n]; //dynamically memory allocation

cout<<"Enter your Sentence:";

cin.get(cp,n,'.');

cout<<"Enter
ed sentence is"<<cp;

return 0;

}


0 Comments had been done yet:

Post a Comment