Click here to Skip to main content
16,009,598 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CRichEditCtrl and UNICODE Pin
sstoyan15-Mar-04 23:15
sstoyan15-Mar-04 23:15 
QuestionHow can i save a text string as a tga file Pin
Orochi14-Mar-04 3:39
Orochi14-Mar-04 3:39 
AnswerRe: How can i save a text string as a tga file Pin
Christian Graus14-Mar-04 15:55
protectorChristian Graus14-Mar-04 15:55 
GeneralURL Does not use a Recognized protocol Pin
muckmail14-Mar-04 2:44
muckmail14-Mar-04 2:44 
GeneralRe: URL Does not use a Recognized protocol Pin
Ravi Bhavnani14-Mar-04 9:20
professionalRavi Bhavnani14-Mar-04 9:20 
Generalisalpha, isalnum Pin
nss14-Mar-04 2:17
nss14-Mar-04 2:17 
GeneralRe: isalpha, isalnum Pin
Michael Dunn14-Mar-04 4:43
sitebuilderMichael Dunn14-Mar-04 4:43 
GeneralRe: isalpha, isalnum Pin
Antti Keskinen14-Mar-04 10:32
Antti Keskinen14-Mar-04 10:32 
As an answer to the first reply:

I wouldn't say 'interesting'. I find it extremely useful that I can use both character symbols and integers to a character stream. Using an integer variable with a character conversion gives me access to symbols that are not normally available in the C/C++ coding syntax, such as scandinavian characters.

Now, for the other questions. Firstly, you should consider using some other stream input function. Read the entire input string in first, then go through the string, removing all invalid characters. The problem with your function above is that when you peek the character, and then test it in against the alphanumeric conversion, you don't explicitly convert the character into an integer. Add an (int) conversion operator before c. This might solve the problem, but an even better implementation is to read the entire string first.

What happens now is that you peek the character, and if it is alphanumeric, it is read into the input stream. If it is not alphanumeric, the character is left into the input stream, and you peek for the next character. As it happens now, the next character is considered alphanumeric, and the cin >> operation executes, and it actually reads everything from the input stream into the buffer, because r has lots of space available.

Here is an alternative implementation that is a bit closer on what you are trying to accomplish:
char buffer[256];
char c;
int nIndex = 0;<DIV>

cout << "Enter string: ";<DIV>

while (c != '\n')
{
   cin >> c; // Alternatively, you could use _getch or cin.read( &c, 1)
   if ( isalpha( (int)c ) )
   {
      buffer[nIndex] = c;
      nIndex++;
   }
}
Not sure if that will work, but test it out & debug if needed.. But you should get the big picture Smile | :)

-Antti Keskinen

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
GeneralRe: isalpha, isalnum Pin
nss15-Mar-04 12:40
nss15-Mar-04 12:40 
QuestionHow do i create window with menu styles Pin
anematollahi14-Mar-04 0:16
anematollahi14-Mar-04 0:16 
AnswerRe: How do i create window with menu styles Pin
Prakash Nadar14-Mar-04 0:27
Prakash Nadar14-Mar-04 0:27 
Generaldoc-view and database problem Pin
heuriskeinner13-Mar-04 23:59
heuriskeinner13-Mar-04 23:59 
GeneralRe: doc-view and database problem Pin
Prakash Nadar14-Mar-04 0:25
Prakash Nadar14-Mar-04 0:25 
GeneralRequired header <conio.h> of C-library Pin
oOomen13-Mar-04 23:48
oOomen13-Mar-04 23:48 
GeneralRe: Required header &lt;conio.h&gt; of C-library Pin
Prakash Nadar14-Mar-04 0:23
Prakash Nadar14-Mar-04 0:23 
GeneralRe: Required header &lt;conio.h&gt; of C-library Pin
oOomen14-Mar-04 2:02
oOomen14-Mar-04 2:02 
GeneralRe: Required header &lt;conio.h&gt; of C-library Pin
Prakash Nadar14-Mar-04 2:20
Prakash Nadar14-Mar-04 2:20 
GeneralRe: Required header <conio.h> of C-library Pin
oOomen14-Mar-04 3:57
oOomen14-Mar-04 3:57 
GeneralRe: Required header &lt;conio.h&gt; of C-library Pin
Prakash Nadar14-Mar-04 6:01
Prakash Nadar14-Mar-04 6:01 
GeneralMFC: Problem using CWnd::SendMessage Pin
Davex_13-Mar-04 17:20
Davex_13-Mar-04 17:20 
GeneralRe: MFC: Problem using CWnd::SendMessage Pin
Ravi Bhavnani13-Mar-04 17:28
professionalRavi Bhavnani13-Mar-04 17:28 
GeneralRe: MFC: Problem using CWnd::SendMessage Pin
Davex_14-Mar-04 4:16
Davex_14-Mar-04 4:16 
GeneralProperty Pages/Sheets/Tab Controls Pin
Anonymous13-Mar-04 14:41
Anonymous13-Mar-04 14:41 
GeneralRe: Property Pages/Sheets/Tab Controls Pin
Prakash Nadar13-Mar-04 15:31
Prakash Nadar13-Mar-04 15:31 
GeneralRe: Property Pages/Sheets/Tab Controls Pin
Ravi Bhavnani13-Mar-04 17:35
professionalRavi Bhavnani13-Mar-04 17:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.