|
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 ?
|
|
|
|
|
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
|
|
|
|
|
.
I guess, OP's query is still unsolved. I totally lost him.
|
|
|
|
|
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())<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 />
}
|
|
|
|
|
Suresh H wrote: for(int j =0; j<=wsize; j++)
{
One correction need to be done here, It should be modified to,
for(int j =0; j < wsize; j++) .
And use isalpha to identify character.
You code should look like this,
for(int j =0; j < wsize; j++)
{
if (isalpha(stemp[j]))
{
FMap[stemp] = offset;
}
}
|
|
|
|
|
Hi Prasad,
Code as no effect its adding all the words.
<br />
<br />
void getoff(char *fname)<br />
{<br />
ifstream fin;<br />
fin.open(fname,ios::in);<br />
<br />
<br />
int wsize;<br />
string stemp;<br />
<br />
while(!fin.eof())<br />
{<br />
fin >> word; <br />
strlwr(word);<br />
wsize = strlen(word);<br />
offset=fin.tellg(); <br />
offset = offset - wsize + 1;<br />
stemp = word;<br />
<br />
for(int j =0; j < wsize; j++)<br />
{<br />
if (isalpha(stemp[j]))<br />
{<br />
FMap[stemp] = offset;<br />
}<br />
}<br />
}<br />
<br />
fin.close();<br />
}<br />
|
|
|
|
|
Here change the for loop as below,
int nIndex = 0;
for (int j = 0; j < wsize; j++)
{
if (isalpha(stemp[j]))
{
FMap[nIndex++] = stemp[j];
}
}
FMap[nIndex] = '\0';
Do your Duty and Don't expect the Result Rate this Post, if I helped You
|
|
|
|
|
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!
|
|
|
|
|
Use _isascii
Come online at:-
jubinc@skype
|
|
|
|
|
Don Box wrote: _isascii
OP wanted to know if given character is in range a-z or A-Z . I wonder, why you have suggested this function ?
|
|
|
|
|
I had placed this question already
But didnt get any answer.
Please give some solution fast
hopefullyyyyyyyyyyyyyyyyyyy
shyam
|
|
|
|
|
sanjay kaledhonkar wrote:But didnt get any answer.
Please give some solution fast
hopefullyyyyyyyyyyyyyyyyyyy
what you want actual Lan Speed which can be easily found out by using GetIpStatisticsEx and if you want LanSpeed printed on LanCard .. i soubt you have to use WMI
|
|
|
|
|
Thanks is in order: sanjay kaledhonkar
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
Programm3r wrote: Thanks is in order:
sanjay kaledhonkar
didn't understand what you want to say .. bro!
|
|
|
|
|
sanjay kaledhonkar wrote: getting LAN speed
You need to know the engine type of your LAN. If you are planning to increase the speed, use a High octane fuel. Tubeless radials will be an added advantage. If I were you, I would not mind spending a little more to get a couple of nitrogen boosters fixed to boost the speed. And you obviously need a speedometer LanoMeter to check the LAN speed. It is available in all leading automobile LanoMobile stores. See you at the international lan race at Tokyo. Bye for now.
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
brahmma wrote: use a High octane fuel.
thats little but costly.. don't you think... but i like lanometer concept.. let make gui for same.. what do you say!
|
|
|
|
|
ThatsAlok wrote: but i like lanometer concept.. let make gui for same.. what do you say!
that is good. Shall we work together and write an article? Lanometer?
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|