?
Solved

Needing help with text processing.

Posted on 2003-03-05
13
Medium Priority
?
203 Views
Last Modified: 2010-04-17
I need to make a program that process text using C++. How do you make text as an input? Is there some kind of algorithm needed or is there just a command I can use?
0
Comment
Question by:blackbrick
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 6

Expert Comment

by:gj62
ID: 8072370
First, you should post this question in the C++ forum.

Second, you need to provide much more detail...

What type of text (fixed format, free-form text, commands, paragraphs, words, etc)?

What do you want to do with the text (read from a file, write to a file, display on screen, format into reports, read as records, etc)?

What platform are you on?  Can you use MFC, or just native C++ classes?

The more info, the better our answers will be...
0
 
LVL 8

Expert Comment

by:Exceter
ID: 8072375
>> process text using C++.

What do you mean by process text?

>> How do you make text as an input?

#include <iostream>

using namespace std;

int main()
{
    char text[50];
    cin >> text;
    cout << endl << "You entered, " << text << endl;

    return 0;
}

>> Is there some kind of algorithm needed or is there just a command I can use?

No, the algorithm is already coded for you. Just call cin to use it.

Exceter
0
 
LVL 6

Expert Comment

by:gj62
ID: 8072408
Oh, and does it have to be C++?  If you are just looking to manipulate text, easier languages come to mind for this purpose, such as Perl.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:taisk
ID: 8075586
AWK is a very good text processing tool as well.  What processing is required?  Are you trying to process the texts within a bigger application?
0
 

Author Comment

by:blackbrick
ID: 8079846
Thanks for the response.

What I have to do is to strip down html codes from an HTML file into a plain TXT file - no codes, no picture, no script etc. So the input is a file.

The HTML file calls the program that I create (meaning I still have to create an IE plug-in but I'll save that for later) and then the program processes it.

My question is how to write a program that reads a file. And maybe some basic concept and commands needed to work with a file (somebody know an url to an online tutorial maybe?). I've never worked with a file before. What I've done so far is only typing in the input and the programs runs and displays the output. So this is completely foreign to me.

I use the basic C++ - the only thing I know for now. I'm not sure if I can make it on time if I have to learn Perl or AWK first.

Sorry I'm having a difficulty explaining this cause English is not my native language.
0
 
LVL 6

Expert Comment

by:gj62
ID: 8080561
The reason I recommended Perl is because it is based on C - you should be able to pick it up pretty fast.  I would be surprised if you can learn to parse and manipulate HTML in C++ any faster.

That said, if you have to create a complete HTML parser, you are in for some work, regardless of what language you choose.  This didn't sound like homework, so you might try to find a class library that can help you.  One open-source library that is in development but claims to have a completed HTML parser is

http://www.odin-consulting.com/OPP/

or you can try:

http://ekhtml.sourceforge.net/
http://msalem.translator.cx/libhtmlparse.html (in C, not C++)

Good luck...
0
 

Author Comment

by:blackbrick
ID: 8087437
Thank you. I haven't got the time to look at those links so I can't yet decide to accept your answer so I'll be back later.
0
 

Author Comment

by:blackbrick
ID: 8097108
Ok, the links should help, but since my original question was about how to get a file as an input in C++, I guess I can use that excuse to say that my question hasn't been answered. LOL. But I did add the question points to 300 which is all I have btw.

So I need to learn on how to work with a file. Could you give an example of a C++ program for one simpler case of working with a file?
0
 
LVL 6

Expert Comment

by:gj62
ID: 8097911
Your first question didn't say text file - it just said text - there is a difference (text can be entered from the keyboard, for example).

Anyhow, there are a large number of ways to work with a text file, but it depends what is in the file as to which method is best.

Can you please answer the following:

1) What is the file of?  Is it formatted (only certain fields on a line)?  

2) What do you want to do with the file once you read it in?

3) What C++ compiler are you using?  If you are on Windows, can you use MFC?

etc...

The more information you provide, the more specific we can be with the answer...
0
 

Author Comment

by:blackbrick
ID: 8102019
1) It' just the kind of text that you type on your notepad and then save it...I don't know what format it's called.

2) It's actually just whatever you think is simple to do. It doesn't feel right to me to make you work too much for only 300 points. It's only an example for me to learn anyway. How about change all "a"s into "b"s?

3) I use C++ from Microsoft Visual Studio and I don't know MFC.
0
 

Author Comment

by:blackbrick
ID: 8102024
Hope they're enough information.
0
 
LVL 6

Accepted Solution

by:
gj62 earned 1200 total points
ID: 8102476
OK - here's a few tutorials on the subject.  Let me know if you need more details...

http://www.cs.rochester.edu/u/srini/csc172/CppFileIo.html

http://www.cs.indiana.edu/classes/h212-lake/streams/streams.html

Perhaps the best tutorial is:  

http://www.eecs.umich.edu/~kieras/eecs280w00website/lecture/filestreams.pdf

Hope this helps...

0
 

Author Comment

by:blackbrick
ID: 8103460
Great. Thank you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Starting up a Project

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question