hello there, i need your help with this C++ program. i am not a computer science
ID: 3762896 • Letter: H
Question
hello there,
i need your help with this C++ program. i am not a computer science major and programming is hard for me.
i need to have the function create_sentence() to creates the dynamic array ofcharacters based on the user input. then, i need the Tfunction to return the address of the 1-darray of characters on the heap or set the pointer to the address by passing the pointeras an argument either explicitly passing the address of the pointer.
please help me if you can. this is what i have so far:
Explanation / Answer
Program:
#include<iostream>
#include<cstring>
using namespace std;
void get_sentence(char s[20]);
void create_sentence(char *s2);
char* Tfunction(char *s2);
int main()
{
char s[20];
char *s2="";
create_sentence(s2);
get_sentence(s);
get_sentence(s2);
cout << s << endl;
cout << s2 << endl;
cout << Tfunction(s2) << endl;
system("pause");
return 0;
}
void get_sentence(char s[20])
{
cin.getline(s,20);
cout << "Enter the sentence: " << endl;
}
void create_sentence(char *s2)
{
int size;
cout << "Enter the size of the array: "<< endl;
cin >> size;
s2=new char[size];
}
char* Tfunction(char *s2)
{
return s2;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.