ignore the return part of the function
I want to the user to input a string.
With that string I want to use a pointer to point to the string and pass it through a function.
When I print the contents of the pointer. It prints junk.
This is where I am stuck, passing a pointer to a string through a function.
Been stuck here for 5 hours googling how to pass a pointer to a string.
#include <iostream>
#include <string>
#include <memory> ///smart pointers
void print(std::string* str_ptr)///the argument must match type std::string*
{
std::cout<<*str_ptr<<"\n\n";
}
void print_smart_pointer(std::shared_ptr<std::string> ptr)
{
std::cout<<*ptr<<"\n\n";
}
///this is a different function, it accepts a c string not an std::string
void print_cstring(constchar* c_str)
{
std::cout<<c_str<<"\n";
}
int main()
{
std::string hello("hello there\n");
std::string* hello_ptr = &hello;
print(hello_ptr);///how to pass the argument
std::string* str_ptr = new std::string("pointer to dynamically allocated string\n");
print(str_ptr);///yhow to pass the argument
std::shared_ptr<std::string> smart_str_ptr = std::make_shared<std::string>("a string pointed to by a smart pointer\n\n");
print_smart_pointer(smart_str_ptr);///how to pass the argument
///c strings
constchar* cstr_ptr ="hello therem\0";
print_cstring(cstr_ptr);///how to pass the argument
char cstr[12] ={'h','e','l','l','o',' ','t','h','e','r','e','\0'};
print_cstring(cstr);///how to pass the argument
}
Hardest part of the program
passing a point to a string
Rules
Encode function
Consonsants and vowels (capital or lowercase) moves 9 to the right
A->J
numbers are turned into capital letters
0 -> A................9->J
Decode function goes back to user input