By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 827 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

who can fix my programme

P: 6
I tried to fix my programme but without success . the idea of the programme is to count the occurence of each similar word and their percentage .

the code:
#include<iostream>

using namespace std;

#include<fstream>
#include<cstring>




int main()
{

ifstream infile ;
ofstream outfile;
char text[300],sec[300];
char*Ptr1,*Ptr2;
int x=0,total=1;



infile.open("sentence.txt");

if(infile.fail()){

cout<<"file cannot be found";

}

outfile.open("analysis.txt");

if (outfile.fail()){

cout<<"file cannot be found";

}

infile.getline(text,300);
infile.getline(sec,300);

Ptr1=strtok(text," ");
Ptr2=strtok(sec," ");

while(Ptr1!='\0'){
x=0;

while(Ptr2!= NULL){
total=total+1;
if(strcmp(Ptr1,Ptr2)==0){

x=x+1;

}

Ptr2=strtok(NULL," ");

}

cout<<Ptr1<<" "<<x<<" "<<(x/total)*100<<endl;
outfile<<Ptr1<<" "<<x<<endl;
Ptr1=strtok(NULL," ");


}
return 0;

}
Oct 1 '06 #1
Share this Question
Share on Google+
2 Replies


Banfa
Expert Mod 5K+
P: 8,916
You will need to decribe the way in which it is not working. Are you getting any compile or run time errors?
Oct 2 '06 #2

P: 6
i am not getting any compile or runtime errors i just have logical errors .

the due date for this assignment is wednesday 4/10
Oct 2 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.