I can't figure out how to read a file word by word. I want to open the file and then read it one word at a time. For example, I'm looking for words that start with d. How would I scan each word of the file to see if it starts with the letter d?
5 15033
I can't figure out how to read a file word by word. I want to open the file and then read it one word at a time. For example, I'm looking for words that start with d. How would I scan each word of the file to see if it starts with the letter d?
After reading the word check whether the position 0 of the string contains d .
If it is then its the word you are lokking for or else skip it. -
char arr[] = "defghi";
-
if(arr[0] == 'd')
-
{
-
/*This word starts with d*/
-
}
-
else
-
{
-
/*skip it*/
-
}
-
Raghuram
After reading the word check whether the position 0 of the string contains d .
If it is then its the word you are lokking for or else skip it. -
char arr[] = "defghi";
-
if(arr[0] == 'd')
-
{
-
/*This word starts with d*/
-
}
-
else
-
{
-
/*skip it*/
-
}
-
Raghuram
How would I get the word though? I don't know how to get one word at a time. I only know how to use getline a little bit.
Here's the code I have: - if(myfile.is_open())
-
{
-
while(! myfile.eof())
-
{
-
myfile >> word;
-
cout << word << endl;
-
// getline(myfile, word);
-
// cout << word << endl;
-
// getline(myfile,line);
-
// cout << line << endl;
-
}
-
myfile.close();
-
}
-
}
-
-
return 0;
-
}
-
It reads the file and outputs one word on a new line, like this:
hello.
my
name
is
joe.
if(myfile.is_open())
{
while(! myfile.eof())
{
myfile >> word;
cout << word << endl;
// getline(myfile, word);
// cout << word << endl;
// getline(myfile,line);
// cout << line << endl;
}
myfile.close();
}
}
return 0;
}
It reads the file and outputs one word on a new line, like this:
hello.
my
name
is
joe.
I'm sorry, but you are reading the file word by word. Just do what it says in Post #2.
I wrote more code. I added two linked lists I need and tried to open the file, read a word at a time, and insert it into the linked list. I don't think I did it right though. When I run the program, it asks the user to input a filename like it's supposed to and accepts the response, but after that, nothing happens. The program just keeps running without doing anything. Feedback of what I did wrong and what I have to do to fix it would be appreciated. Thanks.
Here's my new code:
What is the use of this line -
while(file == "dtext.txt")
-
This will loop continuously.
Change to if loop or else remove it.
Raghuram
Sign in to post your reply or Sign up for a free account.
Similar topics
by: David Erickson |
last post by:
I need to read some (about 15,000) word documents and add some wrappers
around them for importing into a database. What is the best way to read a
..doc file in VB? I would like to save the...
|
by: hokiegal99 |
last post by:
This is not really a Python-centric question, however, I am using
Python to solve this problem (as of now) so I thought it appropiate to
pose the question here.
I have some functions that search...
|
by: Phil Slater |
last post by:
I'm trying to process a collection of text files, reading word by word. The
program run hangs whenever it encounters a word with an accented letter
(like rôle or passé) - ie something that's not a...
|
by: Erpman |
last post by:
I am trying to access the data with in a wav file. I am testing with very
small files in order to keep the code simple to start with.
Basically, im writing the entire wav file to a byte using a...
|
by: Eshban Bahadur |
last post by:
Hello,
I want to read (RTF) files in my VB.NET programme. How can i do it. I apply
the same method of reading text files, but it does not save the formatting of
text like (bold, italics,...
|
by: Jerim79 |
last post by:
I did try to find the answer to this before posting, so this isn't a
knee jerk reaction.
What I am trying to accomplish is to have a script that opens a
cookie, reads a value, and then use a...
|
by: ahammad |
last post by:
Well, the title pretty much describes what I want to do. I want to be able to read the contents of a Word document (*.doc). I also want to be able to read it to a CString object, and then search that...
|
by: byte8bits |
last post by:
How does C++ safely open and read very large files? For example, say I
have 1GB of physical memory and I open a 4GB file and attempt to read
it like so:
#include <iostream>
#include <fstream>...
|
by: shrimpy |
last post by:
hi every one, i am new to python,
and coz i want to write a handy command for my linux machine, to find
a word in all the files which are under the current folder.
the code is half done, but...
|
by: navanova |
last post by:
Greetings,
I have a problem of opening ms word and excel files on my computer. The files are there for a long time. I use to open and modify them. Suddenly, when i try to open the word files, a...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |