Converting text to phonetic alphabet --- if loop problem..
Mar 24, 2010 at 4:23am UTC
Hi all,
I am writing a program that converts text in a standard .txt file into the NATO phonetic alphabet ( a= alfa, b = beta, c = charlie, etc..)
I am having some trouble in the conversion stage of my program.. during my if loop, i get an error message saying "ISO C++ FORBIDS COMPARISON BETWEEN POINTER AND INTEGER" and I am not sure of a way to fix this.
here is the relevant part of my sourcefile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
void readSourceFile ()
{
ifstream myfile;
myfile.open (filename, ios::binary );
if (myfile.is_open())
{
myfile.seekg (0, ios::end);
length = myfile.tellg();
myfile.seekg (0, ios::beg);
buffer = new char [length];
myfile.read (buffer,length);
myfile.close();
cout.write (buffer,length);
cout << endl << endl << endl;
}
else cout << "Unable To Open File, Try A Different Filename." << endl << endl << endl << endl;
}
void convertSourceFile ()
{
ofstream myfile;
myfile.open ("Convertion.txt" );
if (myfile.is_open())
{
int n;
int i;
for ( n = 0, i = 0; i < (length + 1); i++, n++)
{
if (buffer[n] == "A" ){ //THIS IS THE IF LOOP
myfile << "Alfa" ;
}
else if (buffer[n] == "B" ){ //AND OF COURSE THESE TOO..
myfile << "Beta" ;
}
else if (buffer[n] == "C" ){
myfile << "Charlie" ;
}
else if (buffer[n] == "D" ){
myfile << "Delta" ;
}
else if (buffer[n] == "E" ){
myfile << "Echo" ;
}
else if (buffer[n] == "F" ){
myfile << "Foxtrot" ;
}
}
}
}
I know the conversion part is incomplete but I wanted to try a sample before I went ahead and wrote the entire alphabet out..
thanks in advance for and help, much appreciated.
Mar 24, 2010 at 7:07am UTC
Change double quotes for single quotes. ( if (buffer[n] == 'A' )
etc. )
'A' is a single character whilst "A" is a string of two characters ('A' + '\0')
Mar 24, 2010 at 7:23am UTC
ahh, of course, I knew i was just missing something simple..
program is working great now
thanks heaps Danielsson
Topic archived. No new replies allowed.