|
I Hope this[^] will help you.
Regards,
Paresh.
|
|
|
|
|
Check the permissions requested when opening the primary keys for reading. You might be using KEY_ALL_ACCESS when you should only request the privileges you need.
Try using only KEY_QUERY_VALUE|KEY_READ instead and oyu will find it probably works as expected.
|
|
|
|
|
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.
|
|
|
|
|
Why don't you simply check if the value is between 'a' and 'z' or between 'A' and 'Z' ?
|
|
|
|
|
Thanks Cedric Moonen for the response.
ASCII values A – 65 to Z – 90 & a – 97 to z – 122.
But hw to check them in the condition ???
|
|
|
|
|
if ( stemp[j] >= 'a' && stemp[j]<= 'z' ||
stemp[j] >= 'A' && stemp[j]<= 'Z' )
{
// add to map
}
nave
|
|
|
|
|
Suresh H wrote: SCII values A – 65 to Z – 90 & a – 97 to z – 122.
IsCharAlpha
|
|
|
|
|
You can use,
isalpha() API
or
You can check the chars are alphabet or not.
if (((stemp[j] >= 65) && (stemp[j] <= 90) ||
((stemp[j] >= 97) && (stemp[j] <= 122)))
else
Do your Duty and Don't expect the Result Rate this Post, if I helped You
|
|
|
|
|
Hi Appu,
Thanks for the response, I made changes but the code as no effect its adding all the words. Including numbers and special characters.
for(int j =0; j<=wsize; j++)<br />
{<br />
if ( (stemp[j] >= 65) && (stemp[j] <= 90) || <br />
(stemp[j] >= 97) && (stemp[j] <= 122) ) <br />
{<br />
FMap[stemp]=offset; <br />
}<br />
} <br />
}<br />
<br />
Something is wrong in the for loop i am unable to find, what will the cause ?
|
|
|
|
|
Suresh H wrote: if ( (stemp[j] >= 65) && (stemp[j] <= 90) ||
(stemp[j] >= 97) && (stemp[j] <= 122) )
you missed out one bracket and it means the whole condition is wrong
if ( ((stemp[j] >= 65) && (stemp[j] <= 90) )||
((stemp[j] >= 97) && (stemp[j] <= 122)) )
Do your Duty and Don't expect the Result Rate this Post, if I helped You
|
|
|
|
|
i checked it and added brackets but still no effect same output
for(int j =0; j<=wsize; j++)<br />
{<br />
if ( ((stemp[j] >= 65) && (stemp[j] <= 90) || <br />
(stemp[j] >= 97) && (stemp[j] <= 122) ) ) <br />
{<br />
FMap[stemp]=offset; <br />
}<br />
}
|
|
|
|
|
Just copy paste the code, 'coz u r still missing the brackets,
if ( ((stemp[j] >= 65) && (stemp[j] <= 90)) ||
((stemp[j] >= 97) && (stemp[j] <= 122) ) )
the condition is this,
Char should be between A-Z (first &&)
or (||)
Char should be between a-z (second &&)
that is,
if ((&&) || (&&))
Do your Duty and Don't expect the Result Rate this Post, if I helped You
|
|
|
|
|
I copied and pasted but still nt working again the same output
for(int j =0; j<=wsize; j++)<br />
{<br />
<br />
if ( ((stemp[j] >= 65) && (stemp[j] <= 90)) || <br />
((stemp[j] >= 97) && (stemp[j] <= 122)) ) <br />
{<br />
FMap[stemp]=offset; <br />
}<br />
}
|
|
|
|
|
your condition checking is correct but the logic inside the loop is wrong,
i just posted the reply, or refer below
int nIndex = 0;
for (int j = 0; j < wsize; j++)
{
if (((stemp[j] >= 65) && (stemp[j] <= 90)) ||
((stemp[j] >= 97) && (stemp[j] <= 122)))
{
FMap[nIndex++] = stemp[j];
}
}
FMap[nIndex] = '\0';
Do your Duty and Don't expect the Result Rate this Post, if I helped You
|
|
|
|
|
appu i made changes but i am getting error
for this lines
FMap[nIndex++] = stemp[j]; /* Not FMap[stemp] = offset */
error C2679: binary '[' : no operator defined which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
FMap[nIndex] = '\0'; /* NULL termination */
error C2679: binary '[' : no operator defined which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
Now the problem with adding values to Map.
|
|
|
|
|
Is FMap char[] or what?
I don't understand what you are trying to do inside the loop, if FMAp is not a char[] or char* ?
Do your Duty and Don't expect the Result Rate this Post, if I helped You
|
|
|
|
|
using namespace std;
typedef map<string,int> FileMap;
#define SIZE 255
char word[SIZE];
int offset;
FileMap FMap;
i forgot to enable Ignore HTML tags in this message (good for code snippets)
-- modified at 4:30 Friday 30th March, 2007
|
|
|
|
|
So FMap is a map to hold string and int, and you want to store words which has only alphates. If this is the senario you are not supposed to insert an item in the map for every charecter checking. Ok here are my questions?
1) How you are diffentiating the words
2) Do you want to remove the special and numeric values and store the string? or totally discarding the string?
3) Is the int value in the needed, whts it going to do if you just want to store the alpha words?
-- modified at 5:22 Friday 30th March, 2007
Here is the idea to proceed,
1)Read a word from the file
2)check for any special or numeric chars in the word, if you found any break the loop and goto step 4.
3)If all the chars are alpha then insert in the map
4)continue the above steps untill the end
All remaing is only the logical part, think and proceed.
-- modified at 5:25 Friday 30th March, 2007
Do your Duty and Don't expect the Result Rate this Post, if I helped You
|
|
|
|
|
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] >= <code>'a'</code>) && (stemp[j] <= <code>'z'</code>) ||
((stemp[j] >= <code>'A'</code>) && (stemp[j] <= <code>'Z'</code>)))
|
|
|
|
|
May be influenced by the subject line...
Do your Duty and Don't expect the Result Rate this Post, if I helped You
|
|
|
|
|
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
|
|
|
|
|
Hi Appu,,
Thank you very much, code is working i made the changes as below
while(!fin.eof())<br />
{<br />
fin >> word; <br />
wsize = strlen(word);<br />
offset=fin.tellg(); <br />
offset = offset - wsize + 1;<br />
stemp = word;<br />
<br />
bool bValid = true;<br />
<br />
for (int j = 0; j < wsize; j++)<br />
{<br />
if (!isalpha(stemp[j]))<br />
{<br />
bValid = false;<br />
break;<br />
}<br />
}<br />
<br />
if (bValid)<br />
FMap[stemp] = offset;<br />
}
|
|
|
|
|
Parthi_Appu wrote: May be influenced by the subject line...
might be. many people get influenced by subject line
|
|
|
|
|
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 ?
|
|
|
|