473,651 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sort and reading a textfile

Hello,
I just look for a capability to sort several words in view of
alphabet.
An example:
stop is 'opst'
reach is 'aechr'
This should read in a new file so that I can look for same letter
orders. When I find the same orders it is an anagram.
My problem is to sort and to select the textfile. I need dataset for
dataset. What is the best way to realize that.

Many thanks for answer
Jul 22 '05 #1
2 2574
BjoernJackschin a wrote:

Hello,
I just look for a capability to sort several words in view of
alphabet.
An example:
stop is 'opst'
reach is 'aechr'
This should read in a new file so that I can look for same letter
orders. When I find the same orders it is an anagram.
My problem is to sort
take the word and split it into a vector of characters.
sort that vector.
create a new string from the sorted vector
and to select the textfile.
not sure what you mean by that.
I need dataset for
dataset. What is the best way to realize that.


What do you have already?
It's much simpler to tailor an answer to somebody if we
know what level of knowledege we can expect from you and
if we know what parts you can solve on your own.

Usually newbies make the same mistake over and over: They
write to much in one big rush. Divide your problem into
subproblems and solve them. Be prepared to throw away
code.

eg.

you could start with:

enter a word from the user
sort the letters
output the letters

Test what you have so far

move the sorting functionality into a function of its own.

Test what you have so far

open a specific file
read a word
output the word for checking
sort the word (using the previously written function)
output the sorted word
close file

Test what you have so far

modify the inner workings of your program to not read
one word but to read all words in a loop

Test what you have so far

replace the fixed filename with some logic to ask the
user for the filename

*** Whole assignment done ****

The important part is: Do small modifications to your program
and test them!

Be prepared: the above smells like homework. So you need
to show code snippets or your whole program and ask specific
questions about that.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #2
ja*******@hotma il.com (BjoernJackschi na) wrote in message news:<a2******* *************** ****@posting.go ogle.com>...
Hello,
I just look for a capability to sort several words in view of
alphabet.
An example:
stop is 'opst'
reach is 'aechr'
This should read in a new file so that I can look for same letter
orders. When I find the same orders it is an anagram.
My problem is to sort and to select the textfile. I need dataset for
dataset. What is the best way to realize that.

Many thanks for answer


Lucky for you, C++ has a number of types and algorithms ready for you.
For instance, the string type and the sort algorithm will give you
the "stop"->"opst" transformation, with one line of code:
// std::string word = "stop"
std::sort( word.begin(), word.end() );

Now, what do you do with the textfile? Each word goes into a
std::string, and each sorted word into another. You want to keep
these together, so you can use a std::pair<std:: string,std::str ing>
for that. std::multimap<s td::string,std: :string> keeps a sorted
collection of such pairs, so you can quickly lookup "opst".
You'll then find the pair "opst","pos t".

Regards,
Michiel Salters
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2150
by: Anders Eriksson | last post by:
Hello! I'm a beginner at PHP and I wonder how I would go about to read a textfile into an array(hash). The textfile looks like this: A/S=age/sex? A/S/L=age/sex/location? AA=alcoholics anonymous
2
1882
by: Suchi | last post by:
Hi all: I want to read a textfile from an ASP program. My program is like this: Set fso = CreateObject("Scripting.FileSystemObject") workFile=http://localhost/Readme.txt) Set textFile = FSObj.OpenTextFile(workFile) lines = split(textFile.ReadAll, VBCrLf) textFile.Close
16
4780
by: Roy | last post by:
I use a Access 2K application.I am trying to use Chuck Grimsby(clsReadTextFile.txt)class utility to read a text file and then do a import of the same into my database.The question is how to call these in a button event or any other method. Thanks, Roy
2
2594
by: chris | last post by:
Hi there, I am reading in a textfile which looks like this (there is no new line after the last number) 03 98661881 0407 566453 The code to load the textfile looks like this:
2
3022
by: novacreatura | last post by:
Hi, I have a project that's supposed to create a program for a "Dating Service". The first part of the program is to read a textfile of profiles which include names, age, etc...into a string array, and be able to add,edit,remove to the textfile of profiles during runtime. What would be the most efficient way to do this to make it easiest as possible to make changes to the textfile during time and access elements of the array?
1
1424
by: Justin Fancy | last post by:
Hi everyone, I have a textfile which I need to read and compare dates. The text file summarizes every time I do an update to an internet site. Sample output is as follows: Copying humanresources\compensation files from tcinfotest to tcinfo -----------------------
6
22517
by: =?Utf-8?B?UmljaA==?= | last post by:
'--this code works but only reads text into one column when contains multiple cols Dim ds1x As New DataSet Dim ConStr As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dir1A\;Extended Properties=""Text;HDR=No;FMT=Delimited\""" Dim conn1x As New OleDb.OleDbConnection(ConStr) Dim dax1 As New OleDbDataAdapter("Select * from testabc1x.txt", conn1x)
3
2896
by: Arn | last post by:
I just started to learn C++ and have some problem when I read a hole line from a textfile. I would be grateful if anyone can tell me what is wrong with my code. I'm using Borland Developer Studio 2006. //------------------------------------------------------------------------------ // getFile //------------------------------------------------------------------------------ // Read from a textfile // Input: nameList (string) , FILENAME...
1
2808
by: asedt | last post by:
With my Excel macro and two text files I want to create a new textfile containing the first textfile then text from the sheet and then the second textfile. My problem is that i don't know how to append the second textfile. Sub mysub() Dim TempString As String 'Open the first file Dim fileA As Integer
0
8349
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8695
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8460
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7296
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.