473,480 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Stuck on how to read words from text file

11 New Member
So far I have it so that I can open up a file. From there I'm trying to go through the each word of the file and if it starts with an A, I want to throw it into a linked list for words starting with A. So essentially I want to take word #1, if it starts with A or a, throw it in a A linked list. then move onto word #2.... Any suggestions would be extremely helpful. here is the code I have so far....


#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
string fileName;
cout << "Enter the name of the file: ";
cin >> fileName;

ifstream ifs;
ifs.open(fileName.c_str());

if (!ifs.is_open())
{
cout << "That file does not exist" << endl;
system("pause");
}

return 0;
}
Mar 28 '07 #1
7 3303
sicarie
4,677 Recognized Expert Moderator Specialist
You need to declare or implement your linkedlist, get the input, get an individual word, store that, check to see if the first letter is a, if so put it in list, if not, get next word, when words are done, get more input, done while !eof
Mar 28 '07 #2
jimmyjamz
11 New Member
You need to declare or implement your linkedlist, get the input, get an individual word, store that, check to see if the first letter is a, if so put it in list, if not, get next word, when words are done, get more input, done while !eof
My main concern is that I'm unsure of how to go about getting the first word... I've been looking for some kind of tutorial or write up on how to go about doing it, but haven't been to successful.
Mar 28 '07 #3
sicarie
4,677 Recognized Expert Moderator Specialist
My main concern is that I'm unsure of how to go about getting the first word... I've been looking for some kind of tutorial or write up on how to go about doing it, but haven't been to successful.
You have your ifs declared, you can use >> to read in from it, or getline, or a number of methods. A site I frequently link to is cplusplus.com, as they have pretty good tutorials (IMHO).
Mar 28 '07 #4
jimmyjamz
11 New Member
You have your ifs declared, you can use >> to read in from it, or getline, or a number of methods. A site I frequently link to is cplusplus.com, as they have pretty good tutorials (IMHO).
alright thank you.. I'll check that website out now
Mar 28 '07 #5
jimmyjamz
11 New Member
i ended up figuring out how to read the words in word by word... but i'm trying to have it so that if the word starts with a " (quote) that it will look at the next letter in the character array... but I can't get it to take " in single quotes for the comparison. Here is my code... I think there is some kind of \ that will stop it from reading it as a quote and use it as an actual character but I can't remember what it is...

Expand|Select|Wrap|Line Numbers
  1.  else if(character[0] == '"') 
Mar 29 '07 #6
jimmyjamz
11 New Member
i ended up figuring out how to read the words in word by word... but i'm trying to have it so that if the word starts with a " (quote) that it will look at the next letter in the character array... but I can't get it to take " in single quotes for the comparison. Here is my code... I think there is some kind of \ that will stop it from reading it as a quote and use it as an actual character but I can't remember what it is...

Expand|Select|Wrap|Line Numbers
  1.  else if(character[0] == '"') 
nvrmind.. it was the backslash i'm not sure as to why it didnt work earlier.
Mar 29 '07 #7
sicarie
4,677 Recognized Expert Moderator Specialist
Glad you figured it out!

If you have any more trouble, feel free to post again.
Mar 30 '07 #8

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

Similar topics

6
4260
by: Ruben | last post by:
Hello. I am trying to read a small text file using the readline statement. I can only read the first 2 records from the file. It stops at the blank lines or at lines with only spaces. I have a...
2
2114
by: cricfan | last post by:
I'm parsing a text file to extract word definitions. For example the input text file contains the following content: di.va.gate \'di_--v*-.ga_-t\ vb pas.sim \'pas-*m\ adv : here and there :...
8
1526
by: H | last post by:
Now, I'm here with another newbie question .... I want to read a text file, string by string (to do some things with some words etc etc), but I can't seem to find a way to do this String by...
2
1159
by: kulet | last post by:
"2nd post as i noone could do it" Hi guys! Got stuck with this.. I have a chunks of text separated with blanc line. All I need is to take every last 3 lines of that text before the blanc line...
7
1346
by: RallyDSM | last post by:
Hello, I'm currently trying to read a .CSV file and get all the data into an array so I can work with it in the program. Here is what I currently have. Private Sub IntializeData() Dim AL...
7
3012
by: bowlderster | last post by:
Hello, all. This is the text file named test.txt. 1041 1467 7334 9500 2169 7724 3478 3358 9962 7464 6705 2145 6281 8827 1961 1491 3995 3942 5827 6436 6391 6604 4902 1153 1292 4382 9421 1716...
12
7759
by: summy | last post by:
Write a program includes ALL the features: 1.Read the specify file sample.txt and then print the contents of the file on screen. 2.Print each lines of the file in reversed order on screen. ...
0
3824
by: alivip | last post by:
Is python provide search in parent folder contain sub folders and files for example folder name is cars and sub file is Toyota,Honda and BMW and Toyota contain file name camry and file name corola,...
8
33077
by: No Signal X | last post by:
hello i'm having a problem in reading a text file line by line with splitting words, counting the number of lines & words and saving the position of each word i've started with this : public...
0
7046
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,...
0
6908
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...
0
7048
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,...
0
7088
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...
0
6956
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...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
183
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...

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.