Hi, I have just wrote a program in c++ using visual studio 2008. It compiles, runs, and displays the results. However, it shows funky characters in between my two output strings. Here is my code (Comment on top explains what this code is suppose to do):
// This program will allow users to input a string with maximum length of 512.
// First, it will change all uppercase input to lowercase input.
// Then, it will encode the inputed string using the function below.
// The output will display original string and its encoded string
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>
#include <ctype.h>
using namespace std;
const unsigned maxreclen = 512;
int main () {
char userinput[maxreclen + 1];
char conversion[maxreclen + 1];
cout << "Please input your string: " << endl;
cin.getline (userinput,maxreclen);
for (int i=0; i < strlen(userinput); i++) {
if ((userinput[i] >=65) && (userinput[i] <= 90))
conversion[i] = userinput[i] + 32;
else
conversion[i] = userinput[i];
}
char original[] = "abcdefghijklmnopqrstuvwxyz";
char coded[] = "jmartyvwbdlqncxgzekipufohs";
char temp[maxreclen+1];
for (int i = 0; i < strlen(conversion); i++) {
string letterfinder(original);
char x = letterfinder.find(conversion[i]);
temp[i] = coded[x];
}
cout << "Your input is: " << endl;
cout << userinput << endl;
cout << "Lowercase: " << endl;
cout << conversion<< endl;
cout << "Coded: " << endl;
cout << temp << endl;
return 0;
}
Can anyone help me identify my mistake??
Thank you
Bookmarks