Get help on this challenge

Debugging3


Please read this explanation before attempting debugging challenges.


Gaaaah! When I input 'A' it should print out 'b', but I get some weird character instead! Why wont it print my char in this C++ code?

//Made by COM
#include<iostream>
using namespace std;

char& output(char*);
char& changeChar(char);
char& finalOutput(char*);

int main()
{
 char* outp = new char[17];
 outp = &output(outp);
 cout<<outp;
 delete[] outp;
 char inp;
 cin>>inp;
 char& newInp = changeChar(inp);
 char* message = new char[19];
 message = &finalOutput(message);
 cout<<message<<newInp;
 delete[] message;
 return 0;
}

char& changeChar(char inp)
{
 int temp = static_cast<int>(inp);
 temp+=33;
 char newChar = static_cast<char>(temp);
 return newChar;
}

char& output(char* outp)
{
 outp[0] = 'I';
 outp[1] = 'n';
 outp[2] = 'p';
 outp[3] = 'u';
 outp[4] = 't';
 outp[5] = ' ';
 outp[6] = 'o';
 outp[7] = 'n';
 outp[8] = 'e';
 outp[9] = ' ';
 outp[10] = 'c';
 outp[11] = 'h';
 outp[12] = 'a';
 outp[13] = 'r';
 outp[14] = ':';
 outp[15] = ' ';
 outp[16] = '\0';
 char& first = *outp;
 return first;
}

char& finalOutput(char* outp)
{
 outp[0] = 'Y';
 outp[1] = 'o';
 outp[2] = 'u';
 outp[3] = 'r';
 outp[4] = ' ';
 outp[5] = 'n';
 outp[6] = 'e';
 outp[7] = 'w';
 outp[8] = ' ';
 outp[9] = 'c';
 outp[10] = 'h';
 outp[11] = 'a';
 outp[12] = 'r';
 outp[13] = ' ';
 outp[14] = 'i';
 outp[15] = 's';
 outp[16] = ':';
 outp[17] = ' ';
 outp[18] = '\0';
 char& first = *outp;
 return first;
}

Downloadable source code can be found here.


You must be logged in to play.



Challenge by COM.