I am wondering how you read this line of code:
for(const char*c = inputLetters.c_str();*c; ++c)
I understand the inputLetters.c_str() and the ++C, but what does const char*c mean and the *c?
thank you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
char inLetters;
string inputLetters;
inLetters = 0;
int loopCount=1;
int letterCount=0;
// Read Input Data
cout << "Enter a word for the corresponding print out of" << endl << " Civil Aviation Organization Alphabet." << endl;
cin>>inputLetters;
cout<< "The International Civil Aviation Code words for the letters you input are: " << endl;
for(constchar*c = inputLetters.c_str();*c; ++c)
{
/*inLetters =toupper(inLetters);*/
/*cin.get(inLetters);*/
if(loopCount<=26)
letterCount++;
loopCount++;
for(constchar*c = inputLetters.c_str();*c; ++c)
// is the same as
constchar *c;
for ( c = inputLetters.c_str(); *c; ++c )
The 'c' is a pointer. Dereferencing a pointer (*c) does return the value stored in the address pointed to be the pointer.
The convention is that a C-string has value 0 (null) as last character to mark the end of string. Documentation of string::c_str() should mention whether it returns a null-terminated C-string.
The second parameter in the for clause is a conditional expression. It should evaluate to bool. Dereferencing 'c' returns a constchar. Implicit conversion from const char to bool is possible. If the char is 0, then then the boolean value is false. If the char is not null, then the boolean value is true.