How to check the ASCII value ??
-
Parthi_Appu wrote:
if (((stemp[j] >= 65) && (stemp[j] <= 90) || ((stemp[j] >= 97) && (stemp[j] <= 122)))
why bothering comparing to ascii values, when you can use the characters literal ?
if (((stemp[j] >=
'a'
) && (stemp[j] <='z'
) ||
((stemp[j] >='A'
) && (stemp[j] <='Z'
)))
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
toxcct wrote:
why bothering comparing to ascii values, when you can use the characters literal ?
And why to make these comparisons, if isaplha[^] is available ?
Prasad Notifier using ATL | Operator new[],delete[][^]
-
toxcct wrote:
why bothering comparing to ascii values, when you can use the characters literal ?
And why to make these comparisons, if isaplha[^] is available ?
Prasad Notifier using ATL | Operator new[],delete[][^]
prasad_som wrote:
And why to make these comparisons, if isaplha[^] is available ?
yes, i totally agree, i was just beating a bit the worst code author :rolleyes:
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Appu still the problem is there not got the solution still..... i changed the code as below now it only checks for the 1st character if that is valid it will add it to map .. if ( ((stemp[0] >= 65) && (stemp[0] <= 90)) || ((stemp[0] >= 97) && (stemp[0] <= 122)) ) FMap[stemp]=offset; but hwy to check if there is any special character or number in between and hw to add them??
somehow you retrieve the word and put it in stemp then,
while(..)
{
bool bValid = true;
for (j = 0; j < wsize; j++)
{
if (!(((stemp[0] >= 65) && (stemp[0] <= 90)) ||
((stemp[0] >= 97) && (stemp[0] <= 122))))
{
bValid = false;
break;
}
}
if (bValid)
FMap[stemp] = offset;
}
Do your Duty and Don't expect the Result
Rate this Post, if I helped You -
prasad_som wrote:
And why to make these comparisons, if isaplha[^] is available ?
yes, i totally agree, i was just beating a bit the worst code author :rolleyes:
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
:). I guess, OP's query is still unsolved. I totally lost him.
Prasad Notifier using ATL | Operator new[],delete[][^]
-
somehow you retrieve the word and put it in stemp then,
while(..)
{
bool bValid = true;
for (j = 0; j < wsize; j++)
{
if (!(((stemp[0] >= 65) && (stemp[0] <= 90)) ||
((stemp[0] >= 97) && (stemp[0] <= 122))))
{
bValid = false;
break;
}
}
if (bValid)
FMap[stemp] = offset;
}
Do your Duty and Don't expect the Result
Rate this Post, if I helped YouHi Appu,, Thank you very much, code is working i made the changes as below
while(!fin.eof()) { fin >> word; //strlwr(word); wsize = strlen(word); offset=fin.tellg(); offset = offset - wsize + 1; //Insert Words and its offset in to Map stemp = word; bool bValid = true; for (int j = 0; j < wsize; j++) { if (!isalpha(stemp[j])) { bValid = false; break; } } if (bValid) FMap[stemp] = offset; }
-
:). I guess, OP's query is still unsolved. I totally lost him.
Prasad Notifier using ATL | Operator new[],delete[][^]
Hi Prasad, Thank you very much for the help. i made changes a below and its working now perfectly. i had never used isalpha so i was with ascii code, thanks for the info.
while(!fin.eof()) { fin >> word; //strlwr(word); wsize = strlen(word); offset=fin.tellg(); offset = offset - wsize + 1; //Insert Words and its offset in to Map stemp = word; bool bValid = true; for (int j = 0; j < wsize; j++) { if (!isalpha(stemp[j])) { bValid = false; break; } } if (bValid) FMap[stemp] = offset; }
-
Hello All, I am trying a read text file and extracting words from it and adding to a map. I want to add only valid words and eliminate numbers and special character words and then add it to map. Invalid words like 1word , hello# , t2o etc … so I want to eliminate all the number and special characters. Can anyone please help me with this …. strlwr(word); wsize = strlen(word); stemp = word; for(int j =0; j<=wsize; j++) { if ( stemp[j] == '.' || stemp[j] == ';' || stemp[j] == '*' || stemp[j] == '#' && stemp[j] == '!' || stemp[j] == '@' || stemp[j] == '$' || stemp[j] == '%' && stemp[j] == '^' || stemp[j] == '&' || stemp[j] == '(' || stemp[j] == ')' && stemp[j] == '-' || stemp[j] == '+' || stemp[j] == '/' ) break; else FMap[stemp]=offset; } This conditions are very lengthy, is there any way I can reduce it by checking the ASCII value and add them to MAP. Thanking you, Suresh HC.
-
Don Box wrote:
_isascii
OP wanted to know if given character is in range
a-z
orA-Z
. I wonder, why you have suggested this function ?Prasad Notifier using ATL | Operator new[],delete[][^]
-
Look carefully at
for(int j =0; j < wsize; j++)
{
if (isalpha(stemp[j]))
{
FMap[stemp] = offset;
}
}Do you really want to add an entry to FMap every time you find an alpha character, or everytime you find a word with ALL the characters alpha?
Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
cp9876 wrote:
if (isalpha(stemp[j]))
humm!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta Global Interface Table: An Easy Way to Marshal an Interface Pointer[new] VC Forum Q&A :- I/ IV Support CRY- Child Relief and You
-
:) May be influenced by the subject line...
Do your Duty and Don't expect the Result
Rate this Post, if I helped YouParthi_Appu wrote:
:) May be influenced by the subject line...
might be. many people get influenced by subject line
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta Global Interface Table: An Easy Way to Marshal an Interface Pointer[new] VC Forum Q&A :- I/ IV Support CRY- Child Relief and You