Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
i have a program and i should convert int to char into it
but i cant use itoa() because site's judge don't support it
so i wrote this:
xt[i]= rmn+'0';
but i get this error :
Runtime error: Illegal file open (/dev/tty)
How should i convert this?
My code is this : (for palsquare question of USACO)
/*
ID: sa.13781
PROG: palsquare
LANG: C++
*/
#include <iostream>
#include <fstream>
using namespace std;
ofstream fout("palsquare.out");
int tool(char xt[])//CORRECT
{
int p = 0;
while (xt[p] != 0)
p++;
return p;
}
void prt(char xt[])//CORRECT
{
int p = 0;
while (xt[p] != 0)
{
fout << xt[p];
p++;
}
}
void mabna(int a, char xt[], int mab)
{
int ex = 1, tavan = 0, rmn, n;
for (; ex <= a; ex *= mab)
tavan++;
for (int i = tavan - 1; a != 0; i--, a /= mab)
{
rmn = a % mab;
switch (rmn)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
xt[i] = rmn + '0';
break;
case 10:
xt[i] = 'A';
break;
case 11:
xt[i] = 'B';
break;
case 12:
xt[i] = 'C';
break;
case 13:
xt[i] = 'D';
break;
case 14:
xt[i] = 'E';
break;
case 15:
xt[i] = 'F';
break;
case 16:
xt[i] = 'G';
break;
case 17:
xt[i] = 'H';
break;
case 18:
xt[i] = 'I';
break;
case 19:
xt[i] = 'J';
break;
}
}
}
bool mirror(char *xt)//CORRECT
{
int p = 0;
int n = tool(xt);
for (int i = 0; i < (n / 2); i++)
if (xt[i] == xt[n - i - 1])
p++;
if (p == (n / 2))
return true;
return false;
}
void calc(int mab) //CORRECT
{
for (int i = 1; i <= 300; i++)
{
char p[10] = {0}, p2[10] = {0};
mabna(i * i, p2, mab);
if ( mirror(p2) == true )
{
mabna(i, p, mab);
prt(p);
fout << " ";
prt(p2);
fout << "\n";
}
}
}
int main()
{
ifstream fin("palsquare.in");
int mab;
fin >> mab;
calc(mab);
return 0;
}
Can you use sprintf()?
char s[16];
int x = 15;
sprintf(s, "%d", x);
If your int value is single digit, you can just cast it with (char)
If your int value is more than one digit, you can never expect a single char to hold it. char can only hold single character.
int num = 7;
char ch = (num + 48); //same effect as + '0'
cout << ch << endl;
OUTPUT: 7
If your int value is more than single digit. You need char* or char[] to hold the converted data. For example:
int num = 123987;
int len = 6;
int idx = len-1;;
char ch[20];
while(num > 0)
{
ch[idx] = (num%10) + 48;
num /= 10;
idx --;
}
for(int x=0; x<len; x++)
cout << "OUTPUT in char: " << ch[x];
OUTPUT in char: 123987
This is not a perfectly good way to handle this kind of situation, but it may gives you what you asked for.
Related
below is c++ program for decimal to hexadecimal conversion!!
// decimal to hexadecimal conversion
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
string d2h(int n) {
string s, t;
int i = 0;
while (n >= 1) {
t[i] = n % 16;
switch (t[i]) {
case 10:
t[i] = 'A';
break;
case 11:
t[i] = 'B';
break;
case 12:
t[i] = 'C';
break;
case 13:
t[i] = 'D';
break;
case 14:
t[i] = 'E';
break;
case 15:
t[i] = 'F';
break;
default:
break;
}
s[i] = t[i];
n /= 16;
i++;
}
return s;
}
int main() {
int n;
cin >> n;
cout << d2h(n);
return 0;
}
I am getting nothing as output!!
PS C:\Users\anmol\Desktop\c++projectwork> g++ .\dec2hexadec.cpp
PS C:\Users\anmol\Desktop\c++projectwork> ./a
479
PS C:\Users\anmol\Desktop\c++projectwork>
What should i change??
You are not allocating space in s or t for memory. Use s.push_back() instead of s[i].
You'll probably need to reverse the string as well.
t[i] = n % 16; This does not assign the character '0', but rather the number 0. Why don't you just create 16 cases in your switch statement? Or use the ASCII quirk '0' + (n % 16).
// decimal to hexadecimal conversion
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
string d2h(int n) {
string s, t;
string Sign;
int i = 0;
// n is equal to 0? <0 or >0?
if (n == 0){
return "0";
}
if (n < 0){
Sign = "-";
n *= -1;
}
while (n ) {
t.push_back(n % 16) ;
switch (t[i]) {
case 0:
t[i] = '0';
break;
case 1:
t[i] = '1';
break;
case 2:
t[i] = '2';
break;
case 3:
t[i] = '3';
break;
case 4:
t[i] = '4';
break;
case 5:
t[i] = '5';
break;
case 6:
t[i] = '6';
break;
case 7:
t[i] = '7';
break;
case 8:
t[i] = '8';
break;
case 9:
t[i] = '9';
break;
case 10:
t[i] = 'A';
break;
case 11:
t[i] = 'B';
break;
case 12:
t[i] = 'C';
break;
case 13:
t[i] = 'D';
break;
case 14:
t[i] = 'E';
break;
case 15:
t[i] = 'F';
break;
default:
break;
}
s.push_back(t[i]);
n /= 16;
i++;
}
reverse(s.begin(), s.end());
return Sign+s;
}
int main() {
int n;
cin >> n;
cout << d2h(n);
return 0;
}
Well, i made RGB To Hex Conversion. My programm in online compiler works pretty well, but on codewars it has a problem "control may reach end of non-void function". What should i do? Should I remove for loop?
using namespace std;
#include <iostream>
#include <string>
int checkForNumber(int input) {
if (input > 255) return 255;
if (input < 0) return 0;
else return input;
}
string check(int input) {
if (input < 10) return to_string(input);
switch (input)
{
case 10:
return "A";
break;
case 11:
return "B";
break;
case 12:
return "C";
break;
case 13:
return "D";
break;
case 14:
return "E";
break;
case 15:
return "F";
break;
}
}
**string YES(int input) {
string m;
char temp;
for (int i = 0; i < 2; i++) {
m += check(input % 16);
input /= 16;**
//problem is somewhere here
}
temp = m[0];
m[0] = m[1];
m[1] = temp;
return m;
}
int main()
{
string output;
ios_base::sync_with_stdio(false);
int r = 148 , g = 0, b = 211;
r = checkForNumber(r);
g = checkForNumber(g);
b = checkForNumber(b);
output += YES(r) + YES(g) + YES(b);
cout << output;
}
The problem is in your check(int input) function -- consider what happens if the value of the input argument is not in the range [10, 15]. I suggest putting in a default: case that returns something appropriate at the bottom of your switch block.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I want my function to read one char[] and split it into 2 arrays. Both arrays would be one big number, first array is for that number int value and second one is for double values. I must use 2 arrays because this number can be binary, decimal, octal or hex.
void Read(int place[], int &size, int &type, int placedot[], int &sizedot, int &typedot)
{
char reader[limit];
cin >> reader;
size = 1;
while (reader[size] == '.' || size != strlen(reader))
{
size++;
cout << "LOL";
}
cin >> type;
cout << size;
typedot = type;
for (int i = 0; i<size; i++)
{
switch (reader[i])
{
case '0': place[i] = 0; break;
case '1': place[i] = 1; break;
case '2': place[i] = 2; break;
case '3': place[i] = 3; break;
case '4': place[i] = 4; break;
case '5': place[i] = 5; break;
case '6': place[i] = 6; break;
case '7': place[i] = 7; break;
case '8': place[i] = 8; break;
case '9': place[i] = 9; break;
case 'A': place[i] = 10; break;
case 'B': place[i] = 11; break;
case 'C': place[i] = 12; break;
case 'D': place[i] = 13; break;
case 'E': place[i] = 14; break;
case 'F': place[i] = 15; break;
}
}
}
#include <iostream>
#include <string>
int main()
{
std::string str = "3423432432.32445654576654578978905";
std::string strInt;
std::string strDec;
int i = 0;
while('.' != str[i])
strInt += str[i++];
for(++i; i < str.length(); i++)
strDec += str[i];
std::cout << strInt << std::endl << strDec << std::endl;
// now you have the integer part and the decimal part as strings so convert each of them to int
std::cout << std::endl;
return 0;
}
Ok, so this program has been shortened to make it easier to read. There would obviously be more case statements to go along with the amount of variables there are. My question is why does my program get an error every time it runs. It is fine when it compiles but not when I run it.
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
string thearray[22960];
char bigfor[10];
int arrayvar = 0;
int finishedarray;
int a;
int b;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
int j;
// Constants
int variable1 = 0;
int variable2 = 1;
int variable3 = 2;
int variable4 = 3;
int variable5 = 4;
int variable6 = 5;
int variable7 = 6;
int variable8 = 7;
int variable9 = 8;
int variable10 = 9;
for (a = 0; a < 36; a++)
{
switch (a)
{
case 0:
bigfor[variable1] = '0';
break;
case 1:
bigfor[variable1] = '1';
break;
case 2:
bigfor[variable1] = '2';
break;
case 3:
bigfor[variable1] = '3';
break;
case 4:
bigfor[variable1] = '4';
break;
case 5:
bigfor[variable1] = '5';
break;
case 6:
bigfor[variable1] = '6';
break;
case 7:
bigfor[variable1] = '7';
break;
case 8:
bigfor[variable1] = '8';
break;
case 9:
bigfor[variable1] = '9';
break;
}
thearray[arrayvar] = bigfor[variable1] + bigfor[variable2] + bigfor[variable4] +
bigfor[variable5] + bigfor[variable6] + bigfor[variable7] +
bigfor[variable8] + bigfor[variable9] + bigfor[variable10];
arrayvar = arrayvar + 1;
}
finishedarray = arrayvar + 1;
ofstream myfile;
myfile.open("codes.txt");
for (arrayvar = 0; a < finishedarray; a++)
{
myfile << thearray[arrayvar] << endl;
}
myfile.close();
return 0;
}
One problem is that you are reading uninitialized values here:
thearray[arrayvar] = bigfor[variable1]+ bigfor[variable2] + bigfor[variable4] +
bigfor[variable5] + bigfor[variable6] + bigfor[variable7] + bigfor[variable8] +
bigfor[variable9] + bigfor[variable10];
This is undefined behaviour. At this point in the program, only bigfor[variable1] is initialized.
Whatever you are trying to do, I have a feeling there is a simpler way to do it.
The problem was the addition you were doing. The addition will only add the integer-encoded values of the ASCII characters, and result in an integer. This will cause an error because you can't assign an integer to a std::string.
In addition to #juanchopanza's answer, your code can be improved substantially. For example, instead of listing out the indices manually, you can do this instead within your for loop:
std::string bigfor;
for (int a = 0; a < 36; ++a)
{
bigfor += (a + 48);
}
std::ofstream myfile("codes.txt");
for (int i = 0; i < bigfor.size(); ++i)
{
myfile << bigfor[i] << std::endl;
}
I looked through the other questions that also contained these errors. I was not able to find a solution from those questions. Some answers said certain functions weren't implemented but my functions are. I only get the title error when I try to run the program from the VS2012 command line. When I run the program from the IDE, I have no errors and everything is fine.
Visual Studio 2012 Project
TTH.zip
Imgur
Capture_CMD.png
useTTH.cpp
#include <iostream>
#include <string>
#include "tth.h"
using namespace std;
int main()
{
string message;
string choice;
do
{
cout << "Please enter a message: ";
getline(cin, message);
tth tthObject;
tthObject.getMessage(message);
tthObject.encryptMessageOnlyLetters();
cout << endl;
cout << "Encrypt another message? (Yes/No)" << endl;
cout << "> ";
getline(cin, choice);
cout << endl;
}
while(choice.substr(0, 1) == "Y" || choice.substr(0, 1) == "y");
system("PAUSE");
return 0;
}
tth.h
#include <string>
#include <vector>
using namespace std;
class tth
{
public:
tth();
void getMessage(string messageP);
void setMessageOnlyLettersNumberOf16Blocks();
void encryptMessageOnlyLetters();
void messageOnlyLettersToFourByFourLetters();
void matchLetterToNumber();
void calculateAndShowRunningTotalFourByFourNumbers();
void shiftRowsAccordingly();
void calculateAndShowRunningTotalTemp();
void matchNumberToLetter();
void showFourLetterHashNumbers();
private:
string message;
vector<char> messageOnlyLetters;
int runningTotal[4];
char fourLetterHash[4];
int messageLength;
int messageOnlyLettersNumberOf16Blocks;
char fourByFourLetters[4][4];
int fourByFourNumbers[4][4];
int temp[4][4];
};
tth.cpp
#include <iostream>
#include <string>
#include <cctype>
#include "tth.h"
//--------------------------------------------------------------------------------------------------------------
// tth()
//--------------------------------------------------------------------------------------------------------------
// Constructor for the tth class.
// Initializes the elements of the private integer array 'runningTotal' to 0.
// Initializes the elements of the private char array 'fourLetterHash' to 'A'.
//--------------------------------------------------------------------------------------------------------------
tth::tth()
{
for(int i = 0; i < 4; i++)
{
runningTotal[i] = 0;
fourLetterHash[i] = 'A';
}
}
//--------------------------------------------------------------------------------------------------------------
// getMessage(string messageP)
//--------------------------------------------------------------------------------------------------------------
// A public function of the tth class.
// Sets the value of the private string variable 'message' to the value of the string 'messageP' parameter.
// Gives the private char vector 'messageOnlyLetters' only letter elements of the 'message' variable.
//--------------------------------------------------------------------------------------------------------------
void tth::getMessage(string messageP)
{
message = messageP;
messageLength = message.length();
for(int i = 0; i < messageLength; i++)
{
if(isalpha(message[i]))
{
messageOnlyLetters.push_back(message[i]);
}
}
}
//--------------------------------------------------------------------------------------------------------------
// setMessageOnlyLettersNumberOf16Blocks()
//--------------------------------------------------------------------------------------------------------------
// A public function of the tth class.
// Pads the messageOnlyLetters vector with a number 'A' elements equal to modulo 16 of the size of the vector.
// Sets the private int variable 'messageOnlyLettersNumberOf16Blocks' to the quotient of the vector size and 16.
//--------------------------------------------------------------------------------------------------------------
void tth::setMessageOnlyLettersNumberOf16Blocks()
{
int messageOnlyLettersModulo = messageOnlyLetters.size() % 16;
while(messageOnlyLettersModulo != 0)
{
messageOnlyLetters.push_back('A');
messageOnlyLettersModulo = messageOnlyLetters.size() % 16;
}
messageOnlyLettersNumberOf16Blocks = messageOnlyLetters.size() / 16;
}
//--------------------------------------------------------------------------------------------------------------
// encryptMessageOnlyLetters()
//--------------------------------------------------------------------------------------------------------------
// A public function of the tth class.
// Executes the 'setMessageOnlyLettersNumberOf16Blocks()' once.
// Executes other functions of the tth class a number of times equal to 'messageOnlyLettersNumberOf16Blocks'.
//--------------------------------------------------------------------------------------------------------------
void tth::encryptMessageOnlyLetters()
{
setMessageOnlyLettersNumberOf16Blocks();
for (int i = 0; i < messageOnlyLettersNumberOf16Blocks; i++)
{
messageOnlyLettersToFourByFourLetters();
matchLetterToNumber();
calculateAndShowRunningTotalFourByFourNumbers();
cout << endl;
shiftRowsAccordingly();
calculateAndShowRunningTotalTemp();
cout << endl;
matchNumberToLetter();
showFourLetterHashNumbers();
cout << endl;
}
}
//--------------------------------------------------------------------------------------------------------------
// messageOnlyLettersToFourByFourLetters()
//--------------------------------------------------------------------------------------------------------------
// A public function of the tth class.
// Sets the elements of the private char 2D array 'fourByFourLetters' to the elements of 'messageOnlyLetters'.
// Reduces the size of a non-empty messageOnlyLetters by 16 elements.
//--------------------------------------------------------------------------------------------------------------
void tth::messageOnlyLettersToFourByFourLetters()
{
int count = 0;
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
fourByFourLetters[i][j] = messageOnlyLetters[count];
count++;
}
}
if(!(messageOnlyLetters.empty()))
{
messageOnlyLetters.erase(messageOnlyLetters.begin(), messageOnlyLetters.begin() + 16);
}
}
//--------------------------------------------------------------------------------------------------------------
// matchLetterToNumber()
//--------------------------------------------------------------------------------------------------------------
// A public function of the tth class.
// Sets the elements of the private int 2D array 'fourByFourNumbers' to a number 0 - 25.
// The number is determined by the ASCII value of a 'fourByFourLetters' element.
//--------------------------------------------------------------------------------------------------------------
void tth::matchLetterToNumber()
{
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
switch(static_cast<int>(fourByFourLetters[i][j]))
{
case 65:
case 97:
fourByFourNumbers[i][j] = 0;
break;
case 66:
case 98:
fourByFourNumbers[i][j] = 1;
break;
case 67:
case 99:
fourByFourNumbers[i][j] = 2;
break;
case 68:
case 100:
fourByFourNumbers[i][j] = 3;
break;
case 69:
case 101:
fourByFourNumbers[i][j] = 4;
break;
case 70:
case 102:
fourByFourNumbers[i][j] = 5;
break;
case 71:
case 103:
fourByFourNumbers[i][j] = 6;
break;
case 72:
case 104:
fourByFourNumbers[i][j] = 7;
break;
case 73:
case 105:
fourByFourNumbers[i][j] = 8;
break;
case 74:
case 106:
fourByFourNumbers[i][j] = 9;
break;
case 75:
case 107:
fourByFourNumbers[i][j] = 10;
break;
case 76:
case 108:
fourByFourNumbers[i][j] = 11;
break;
case 77:
case 109:
fourByFourNumbers[i][j] = 12;
break;
case 78:
case 110:
fourByFourNumbers[i][j] = 13;
break;
case 79:
case 111:
fourByFourNumbers[i][j] = 14;
break;
case 80:
case 112:
fourByFourNumbers[i][j] = 15;
break;
case 81:
case 113:
fourByFourNumbers[i][j] = 16;
break;
case 82:
case 114:
fourByFourNumbers[i][j] = 17;
break;
case 83:
case 115:
fourByFourNumbers[i][j] = 18;
break;
case 84:
case 116:
fourByFourNumbers[i][j] = 19;
break;
case 85:
case 117:
fourByFourNumbers[i][j] = 20;
break;
case 86:
case 118:
fourByFourNumbers[i][j] = 21;
break;
case 87:
case 119:
fourByFourNumbers[i][j] = 22;
break;
case 88:
case 120:
fourByFourNumbers[i][j] = 23;
break;
case 89:
case 121:
fourByFourNumbers[i][j] = 24;
break;
case 90:
case 122:
fourByFourNumbers[i][j] = 25;
break;
default:
cout << "Hmmmm";
}
}
}
}
//--------------------------------------------------------------------------------------------------------------
// calculateAndShowRunningTotalFourByFourNumbers()
//--------------------------------------------------------------------------------------------------------------
// A public function of the tth class.
// Calculates and sets the elements of 'runningTotal' using an accumulator with 'fourByFourNumbers'.
// Displays a command line message with each element of 'runningTotal'.
//--------------------------------------------------------------------------------------------------------------
void tth::calculateAndShowRunningTotalFourByFourNumbers()
{
cout << endl;
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
runningTotal[i] = runningTotal[i] + fourByFourNumbers[j][i];
}
runningTotal[i] = runningTotal[i] % 26;
cout << runningTotal[i] << " ";
}
}
//--------------------------------------------------------------------------------------------------------------
// shiftRowsAccordingly()
//--------------------------------------------------------------------------------------------------------------
// A public function of the tth class.
// Sets the elements of the private int 2D array 'temp' to a rearranged version of 'fourByFourNumbers'.
// Elements of rows 1 - 3 are shifted in a circular pattern.
// Row 1 elements are shifted to the left by 1 index. Row 2 elements are shifted to the left by 2 indicies.
// Row 3 elements are shifted to the left by 3 indicies. Row 4 elements are swapped: 1 <> 4 and 2 <> 3.
//--------------------------------------------------------------------------------------------------------------
void tth::shiftRowsAccordingly()
{
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
if(i == 0)
{
if(j == 3)
{
temp[i][j] = fourByFourNumbers[i][j - 3];
}
else
{
temp[i][j] = fourByFourNumbers[i][j + 1];
}
}
else if(i == 1)
{
if(j == 2)
{
temp[i][j] = fourByFourNumbers[i][j - 2];
}
else if(j == 3)
{
temp[i][j] = fourByFourNumbers[i][j - 2];
}
else
{
temp[i][j] = fourByFourNumbers[i][j + 2];
}
}
else if(i == 2)
{
if(j == 1)
{
temp[i][j] = fourByFourNumbers[i][j - 1];
}
else if(j == 2)
{
temp[i][j] = fourByFourNumbers[i][j - 1];
}
else if(j == 3)
{
temp[i][j] = fourByFourNumbers[i][j - 1];
}
else
{
temp[i][j] = fourByFourNumbers[i][j + 3];
}
}
else
{
if(j == 1)
{
temp[i][j] = fourByFourNumbers[i][j + 1];
}
else if(j == 2)
{
temp[i][j] = fourByFourNumbers[i][j - 1];
}
else if(j == 3)
{
temp[i][j] = fourByFourNumbers[i][j - 3];
}
else
{
temp[i][j] = fourByFourNumbers[i][j + 3];
}
}
}
}
}
//--------------------------------------------------------------------------------------------------------------
// calculateAndShowRunningTotalTemp()
//--------------------------------------------------------------------------------------------------------------
// A public function of the tth class.
// Calculates and sets the elements of 'runningTotal' using an accumulator with 'temp'.
// Displays a command line message with each element of 'runningTotal'.
//--------------------------------------------------------------------------------------------------------------
void tth::calculateAndShowRunningTotalTemp()
{
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
runningTotal[i] = runningTotal[i] + temp[j][i];
}
runningTotal[i] = runningTotal[i] % 26;
cout << runningTotal[i] << " ";
}
}
//--------------------------------------------------------------------------------------------------------------
// matchNumberToLetter()
//--------------------------------------------------------------------------------------------------------------
// A public function of the tth class.
// Sets the elements of the private char 2D array 'fourLetterHash' to a letter A - Z.
// The letter is determined by the value of a 'runningTotal' element.
//--------------------------------------------------------------------------------------------------------------
void tth::matchNumberToLetter()
{
for(int i = 0; i < 4; i++)
{
switch(runningTotal[i])
{
case 0:
fourLetterHash[i] = 'A';
break;
case 1:
fourLetterHash[i] = 'B';
break;
case 2:
fourLetterHash[i] = 'C';
break;
case 3:
fourLetterHash[i] = 'D';
break;
case 4:
fourLetterHash[i] = 'E';
break;
case 5:
fourLetterHash[i] = 'F';
break;
case 6:
fourLetterHash[i] = 'G';
break;
case 7:
fourLetterHash[i] = 'H';
break;
case 8:
fourLetterHash[i] = 'I';
break;
case 9:
fourLetterHash[i] = 'J';
break;
case 10:
fourLetterHash[i] = 'K';
break;
case 11:
fourLetterHash[i] = 'L';
break;
case 12:
fourLetterHash[i] = 'M';
break;
case 13:
fourLetterHash[i] = 'N';
break;
case 14:
fourLetterHash[i] = 'O';
break;
case 15:
fourLetterHash[i] = 'P';
break;
case 16:
fourLetterHash[i] = 'Q';
break;
case 17:
fourLetterHash[i] = 'R';
break;
case 18:
fourLetterHash[i] = 'S';
break;
case 19:
fourLetterHash[i] = 'T';
break;
case 20:
fourLetterHash[i] = 'U';
break;
case 21:
fourLetterHash[i] = 'V';
break;
case 22:
fourLetterHash[i] = 'W';
break;
case 23:
fourLetterHash[i] = 'X';
break;
case 24:
fourLetterHash[i] = 'Y';
break;
case 25:
fourLetterHash[i] = 'Z';
break;
default:
cout << "Hmmmm";
}
}
}
//--------------------------------------------------------------------------------------------------------------
// showFourLetterHashNumbers()
//--------------------------------------------------------------------------------------------------------------
// A public function of the tth class.
// Displays a command line message with each element of 'fourLetterHash'.
//--------------------------------------------------------------------------------------------------------------
void tth::showFourLetterHashNumbers()
{
for(int i = 0; i < 4; i++)
{
cout << fourLetterHash[i] << " ";
}
}
EDIT
Gah. I put so much effort into this post just to find out it was a simple problem with command line compiling. Thanks for the answers.
Answer
Use the command below to compile the definition file and main program file.
cl tth.cpp useTTH.cpp
You should compile both tth.cpp and useTTH.cpp
with command line:
cl tth.cpp useTTH.cpp
You forgot to include all your source files in your compiler command. As tth.cpp is not included, it cannot find the symbols corresponding to the functions/variables defined there.