comparing strings and characters
Author |
Message |
weijie
|
Posted: Thu Jun 03, 2010 8:00 pm Post subject: comparing strings and characters |
|
|
I need to compare strings of words (which extracted from a txt file) with local alphabet (a to z).
the problem accur when i using strcmp . anyone can help ?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
char* alphe;
int i,j;
int alphe_flag[256]={0};
string line;
ifstream myfile ("example.txt");
if(myfile.is_open()){
while(!myfile.eof()){
getline(myfile,line);
alphe="e";
for(i=0;i<line.length();i++){
for(j=0;j<25;j++){
if(!strcmp(line[i],alphe))
alphe_flag[i]+=1;
alphe++;}}
myfile.close();
}
else cout<<"Unable to open file";
cout<<alphe_flag[5]<<endl;
return 0;
} |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
jcollins1991
|
Posted: Thu Jun 03, 2010 8:43 pm Post subject: Re: comparing strings and characters |
|
|
Before you expect people to read your code try using the code tags
and use the same bracketing throughout your code... Right now your code isn't even readable... |
|
|
|
|
![](images/spacer.gif) |
Homer_simpson
![](http://compsci.ca/v3/uploads/user_avatars/18138546704b4d2a3b2e50e.gif)
|
|
|
|
![](images/spacer.gif) |
|
|