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;
} |
|
|
|
|
|
Sponsor Sponsor
|
|
|
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... |
|
|
|
|
|
Homer_simpson
|
|
|
|
|
|
|