I don't get it. so i have a program. the follow function is executed when I make a selection on the main menu of the program.
Only when i write "cin.getline (ch2,21);"twice this function works right. It prompts you,then you write your string, and it prints the correct values.
if i type "cin.getline (ch2,21);" once, it will just skip the line that asks you to type in a string.. what's the deal??
Code:
void StringType(void)
{
char ch2[21];
char conti6;
int *strp;
int straddr;
cout << endl;
cout << endl;
cout << "Enter a string (20 char max):";
//cin >> ch2;
cin.getline (ch2,21);
cin.getline (ch2,21);
strp = (int*)(&ch2);
straddr = int(strp);
cout << endl;
cout << endl;
cout << "Address:0x";
straddr = int(strp); //bit shifting for output formatting
straddr &= 0xFF000000;
straddr = straddr >> 24;
straddr &= 0x000000FF;
if(straddr < 16) cout << "0";
cout << hex << straddr << " ";
straddr = int(strp);
straddr &= 0x00FF0000;
straddr = straddr >> 16;
if(straddr < 16) cout << "0";
cout << hex << straddr << " ";
straddr = int(strp);
straddr &= 0x0000FF00;
straddr = straddr >> 8;
if(straddr < 16) cout << "0";
cout << hex << straddr << " ";
straddr = int(strp);
straddr &= 0x000000FF;
if(straddr < 16) cout << "0";
cout << hex << straddr << " "; // bit shifting end.
cout << endl;
cout << "ASCII code:0x ";
for(int j = 0; j != 21; j++)
{
if(int(ch2[j] == 0))
{
cout << "00";
break;
}
cout << int(ch2[j]) << " ";
}
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
while(1)
{
cout << "press 'c' and then enter to continue:";
cin >> conti6;
cout << endl;
if(conti6 == 'c' || conti6 == 'C') break;
}
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
}