| | |
pls help
![]() |
•
•
Join Date: May 2006
Posts: 13
Reputation:
Solved Threads: 0
hello,
am doing a project for my school . am asked to ,
1. open a file
2. tokensise the contents and then change the case of all the letters to lower case
3. search for all the words in tat file with another file
so there are 2 files one contails the file that is tokenised and the other a list of words (like a database) .
i need to search that database for all the words in the file that ve tokenised
the program i ve written is in c++ . am having a few problems with matching . can someone pls help
am doing a project for my school . am asked to ,
1. open a file
2. tokensise the contents and then change the case of all the letters to lower case
3. search for all the words in tat file with another file
so there are 2 files one contails the file that is tokenised and the other a list of words (like a database) .
i need to search that database for all the words in the file that ve tokenised
the program i ve written is in c++ . am having a few problems with matching . can someone pls help
C++ Syntax (Toggle Plain Text)
#include<iostream.h> #include<string.h> #include<fstream.h> #include<conio.h> main() { // opening a file for reading ifstream in ("d:/programming/text.txt"); if(!in) { cout<<"cannot open text \n"; return 0; } char line[80]; char* p; //opening a file for writing ofstream out("d:/programming/match.txt"); if(!out){ cout<<"cannot open match"; return 1; } do{ in.getline(line,80);//getting the line from the file to be read p=strtok(line," " );//tokenising the file while(p){ out<<p<<"\n";//putting all the tokens in the file for writing p=strtok(NULL," "); } }while (in); out.close(); in.close(); char line1[80]; char line2[80]; bool eof(); ifstream in1 ("d:/programming/whitelist.txt"); if(!in1) { cout<<"cannot open whitelist \n"; return 1; } ifstream in2 ("d:/programming/match.txt"); if(!in2) { cout<<"cannot open match \n"; return 0; } do{ in1.getline(line1,80);// get the tokens from the file cout<<"line1="<<line1<<"\n"; do{ in2.getline(line2,80); // get the token from the data base cout<<"line2="<<line2<<"\n"; int p1=strcmp(line1,line2);//compare if(p1==0) { cout<<"match \n"; } else{cout<<"no \n";} }while (in2 ); cout<<"over\n"; }while (in1 ); in1.close(); in2.close(); getch(); return 0; }
#include<iostream.h>
#include<string.h>
#include<fstream.h>
You must be using an ancient c++ compiler -- maybe Turbo C++? If you want to learn c++ language you will have to toss that compiler into the bit bucket and get a modern one -- Dev-C++ is a good one.
#include<string.h>
#include<fstream.h>
You must be using an ancient c++ compiler -- maybe Turbo C++? If you want to learn c++ language you will have to toss that compiler into the bit bucket and get a modern one -- Dev-C++ is a good one.
Toss out all that C code and replace it with c++. use std::string and >> insert operator and you don't have to do any tokenizing at all. Here's an example
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> #include <algorithm> using namespace std; int main() { string word; // stay in the loop until you press Ctrl+Z <Enter> while( cin >> word ) { // convert the word to lower-case transform(word.begin(),word.end(),word.begin(),::tolower); // now find the word in the database (not shown here) cout << word << endl; } cout << "done " << endl; return 0; }
![]() |
Similar Threads
- windows xp installation error!! pls help! (Troubleshooting Dead Machines)
- Help me remove Online Poker Pop up pls (Viruses, Spyware and other Nasties)
- hi friends pls help me out (C++)
- pls.help me im begging you!!! (C)
- pls... i need help!!! (C)
- Pls Hlp me with Hijackthis log file. (Viruses, Spyware and other Nasties)
- Pls help with my HJT log (Viruses, Spyware and other Nasties)
- can somebody pls. help me out with my HJT log.. (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: GUI Suggestions
- Next Thread: sequencer
| Thread Tools | Search this Thread |
action api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node noob output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets







it worked wel . now using trhe STL for most of the things