C++ :: Word By Word From A Line In File?
Aug 14, 2014
ow to read word by word from a line in file into struct. Say for example:
12345 Joe Lim KH879.00
12233 Kay Suet Yee35.98
to
struct master {
unsigned short int IDnum;
char name[30];
float salesCustomer;
};
View 1 Replies
ADVERTISEMENT
Jun 25, 2014
Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.
I'm having trouble receiving that random word and I'm getting the definitions from the file.
Here's my code:
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
[Code] ....
This is what is in the words.txt file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet
View 3 Replies
View Related
Apr 7, 2013
I have a text file where in each line is 3 words and 2 int type numbers. I'm doing search by word and I want to print out to the screen the whole line where that word was found (the words is repeated in some lines). My search looks like this:
Code:
#include<iostream>
#include<string>
#include<fstream>
#include<stdlib.h>
#include <vector>
using namespace std;
int main(){
vector <string> words;
string str, paieska;
[Code] .....
How to print line(s) where I found that word?
View 9 Replies
View Related
Feb 18, 2013
I am building a linked list and i need to display function i have. The display function displays all the letters of the word entered instead of the word itself. below is my struct, one of my functions and the display function.
Code:
//-----------struct ------------//
struct Node
{
char data;
struct Node *next;
}*Head;
[code]....
View 1 Replies
View Related
Oct 24, 2013
I'm learning programming, and C++. I've got a question, but I couldn't solve my problem so far. I need to use arrays and only basic stuff to solve this:
Create a program that reads a word from the user and then print (cout) this word on contrary. It's simple, I know, but I can't do it,. I've tried some stuff but I don't get how I will get the proper values to do this. All I know is that I can use variable.lenght().
View 7 Replies
View Related
Mar 20, 2013
I have a problem to open word document into turbo c++. i don't know how to open if the documents are in word format.
View 1 Replies
View Related
Dec 27, 2013
I want a program to display as follows..
if i enter mohandas karamchand gandhi i want output as M K Gandhi.....
i want the c++ code for this program..my error is i am not able to erase the letters of first 2 words..ie my output is Mohandas Karamchand Gandhi..
View 2 Replies
View Related
Apr 25, 2012
I've taken part the text into 1 word per line, but I can't figure out how to printf every word only once and then add (%d) in the end to show how many repetitions of that word there are.
Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main(){
char *oneword;
[Code] ....
View 3 Replies
View Related
Dec 20, 2013
I have text (string) and I want to find a given word (it's ok!) and then insert another given word after the first word. The original string is beeing copied into a new string. But something is going wrong!!! Where is my mistake?
(I have some patches...)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//insert "new_word" after each occurence of "word"
int main(){
char A[100]="In the sentence words the and the.";
[Code]...
View 8 Replies
View Related
Aug 6, 2013
int countTextWords(ifstream * file)
{
string textWord;
int wordCount = 0;
while((*file) >> textWord)
{
wordCount++;
}
return wordCount;
}
for some reason, (*file) >> textWord will not read words into the string. What am I doing wrong?
View 9 Replies
View Related
May 29, 2014
I am working on a bonus question for school. By using #include <iostream> and #include <string>, I need the user to input a sentence getline(cin,sentence). Move the first word of that sentence to the end.
example:
Enter a line of text.
MAC101 is the class
rephrased that line to read:
is the class MAC101
View 12 Replies
View Related
Aug 10, 2012
How to get line number on mouse position in Microsoft word document using winWordControl within windows form?
View 1 Replies
View Related
Apr 25, 2013
i'm making a program for basic data entry.i have also included search feature which uses strcmpi() function.if i have a file name'report on tigers' and someone searched for 'tigers' then that person will not find the required file.any way i can overcome that ?
View 2 Replies
View Related
Aug 12, 2014
How would one go about doing this? I am very fond with Windows I/O, but not so much with this subject. I am decent with fstream, probably not as skilled at it as I should be, but I assume <fstream> would be a better choice, since it isn't locked to Windows.
Anyway, say I have a .txt file like this:
Bill is a cow.
Bill likes meat.
Bob is a pig.
Bob and Bill are friends.
And I want to count the number of times "Bill" is written. How would I do that?
View 5 Replies
View Related
Jun 27, 2013
I have done an exercise from "Thinking in C++" to print text from a file to the console one line at a time, with the user pressing enter to get the next line.
My original code is below, how could I change it for one word at a time?
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
[Code] .....
I tried to alter my program to print one word at a time by changing "getline(in, word)" to "in >> word", but it prints each new word on a new line, the only input I have found to make the next word appear is Enter, I assume that's why.
Is there a way to make it print one word at a time when the user says, but on the same line?
View 4 Replies
View Related
Sep 23, 2013
HOW TO JUMBLE A WORD COMING FROM A FILE?
FILE *DOCU;
DOCU = fopen ("file.txt", "r");
if (DOCU == 0) {
printf ("
Failed to open!
[Code] .....
then what's next?
View 13 Replies
View Related
Sep 24, 2013
HOW TO SHUFFLE A WORD COMING FROM A FILE?
FILE *DOCU;
DOCU = fopen ("file.txt", "r");
if (DOCU == 0) {
printf ("
Failed to open!
[Code] .....
View 4 Replies
View Related
May 24, 2014
I have a C++ program that performs calculations on numbers in a text file. However, suppose we have additional words in the text file such as "Title". In this instance, the program will not calculate the numbers in the file because of the text.
How do we remove text from a file using the C++ program? e.g. if I wanted to specify the program to remove any instances of the word "Title", how would I do it?
View 1 Replies
View Related
Apr 26, 2013
im trying to have the nickanme set to be a random name from a text fille full of nickanmes i dont know how to do it heres my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluorineFx;
using FluorineFx.Messaging.Adapter;
[code].....
View 3 Replies
View Related
Mar 23, 2014
I was asked to create a program to find word frequencies, word length in a text file. I am able to use map to do the frequencies part but don't know how to sort the the output accordingly to the length of the words. The example output that I should get is
1 a. 362
i. 157
2 an. 122
at. 201
3 add. 2
age. 1
int main(void) {
static const char* file = "demo.txt";
map<string, unsigned int> wcount; {
ifstream fileStream(file);
[Code] .....
View 10 Replies
View Related
Jul 26, 2014
I've written a function that has to receive a word as parameter, and then has to find the amount of times that word (uppercase & lowercase) occurs in a text file:
For example, if the word "the" is sent as a parameter, the total amount of times the words "the" and "THE" occurs in the text file, has to be calculated.
However, my function is not displaying the correct amount, what is wrong with my function:
int WordCount :: countWords(string wrd)
{
int counter=0;
string temp = "";
[Code].....
View 1 Replies
View Related
Nov 21, 2014
My goal is to open a .txt file and replace words in it then overwrite it. My goal is half way done. It couts it perfectly, but I am having a hard time overwriting the whole text file exactly how it couts it. I want the text to be exactly how it is displayed. In this example, I want to replace "ABC" with "DEF".
Text file "A.txt":
1 2 ABC 4 5
6 ABC 8
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main() {
string Y;
fstream IN("A.txt", ios::in | ios::out);
[Code] ......
View 3 Replies
View Related
Nov 24, 2012
The user will first enter the file name to be processed. The program can do the following 5 tasks:
1. Count the number of words
2. Count the number of alphabets (without punctuation marks)
3. Count number of sentences.
4. Count the frequency of each vowel.
5. Count frequency of the following three words individually: FAST, computer and engineering
There should be a proper menu through which the user can select the desired task. The program should continue until the user asks to terminate it.
Here is what i have done so far:
#include <iostream>
#include <cstring>
#include <fstream>
#include <cstdlib>
using namespace std;
int main(void)
{
int opt=0; //option number
ifstream fin;
string filename;
[Code]...
There are a few problems.
1- When I enter option 'q', an infinite loop starts.
2- The first time, the program gives the correct value. After that, each time it gives answer ZERO.
3- The last part is not working. I experimented something which failed. I don't know how to do the last part.
View 1 Replies
View Related
Apr 26, 2013
I got this code here id like for it to pick up a random word from a text file and use it as the nick in this line
Code:
SetNick(GetRandomString(10));
how could i do it heres the full code for the client
Code: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluorineFx;
using FluorineFx.Messaging.Adapter;
[Code] ....
View 8 Replies
View Related
Jun 5, 2013
i want to create a program (in c++ or c#) that will play mp3 files but also display a word file with the lyrics of the mp3 song playing. so if i choose a mp3 file from a list, the lyric file for that song should also be displayed. i have all the mp3 and lyric files saved on the computer so my problem is how can i link the files?
View 5 Replies
View Related
Oct 31, 2013
I am trying to pull my words randonly from a wordbank .txt file and so far i have this
#include <iostream>
#include <cctype>
#include <fstream>
using namespace std;
string word;
char knownLetters[]; // The word could be of any length
int stages = 6; // Our hangman has 6 stages, so the player starts with 6 lives
[Code] .....
View 1 Replies
View Related