C++ :: Search By Word In Text File And Print Out Whole Line On Screen
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
ADVERTISEMENT
Apr 1, 2014
i've been trying to figure out to search for a word in a text file and then display everything in the same row as the word found int ie this is whats in the file
john doe 3/21/1920 tech support review team 45,000
so user wants to find tech..and everything associated with it.
so program search for tech, when it does it then display the whole row.
john doe 3/21/1920 tech support review team 45,000
I can figure out how to search for a word, but no clue how to get it to then print out the row. This is all I can figure out to do.
ifstream FileSearch;
FileSearch.open("employee");
if(FileSearch.is_open())
{string letters;// search word would be store here
string row; ??stores entire row as string
while(1)
[Code]....
View 14 Replies
View Related
Jun 15, 2013
I seem to be missing a concept or 2 here ... I am tasked with writing a program that reads text from a file and outputs each line to the screen as well as to another file PRECEDED by a line number ...
In addition, I have to Print the line number at the start of the line and right-adjusted in a field of 3 spaces ...
Follow the line number with a colon then 1 space, then the text of the line.
Another kicker, is I have to grab the data 1 character at a time and write code to ignore leading blanks on each line.
Here is what I have so far:
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cctype>
using namespace std;
int main() {
char next;
int count = 0;
[Code] ....
View 7 Replies
View Related
Oct 28, 2013
I'm trying to make a program that will search for a line in a text file using a non default delimitor at the start of the line. An example line in the text file would be as follows:
F Mary Smyth, 19, United Kingdom
I have been able to use the find function to search for and return the 'F' character but would like it to then display the whole corresponding line. Is this possible with the find function?
ifstream readFromFile("data.txt");
string Destinations[1] = {"F "};
string data;
while(!readFromFile.eof()){
getline(readFromFile,data);
[code]...
View 2 Replies
View Related
Apr 25, 2013
I have written the following code but i am stuck. Write a program that will prompt the user for a file name and open that file for reading. Print out all the information in the file, numbering each new line of text.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
int main()
{
char line[81], filename[21], c;
int i = 1;
FILE *inFile;
[code]....
View 3 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
May 10, 2013
This is a small program that reads a line from the screen, takes the ASCII values from the entered text, and edits it. Next, the ASCII values are reinterpreted (am i misspelling?) as text, and displayed. However, my final output has (allways?) at least 7 characters, even if you enter only one. I'm also trying to accomplish, that the part of the string which isn't filled, will be printed empty. In spaces.
compiled with -std=c99.
Code:
#include <stdio.h>
int main(){
int maxsize;
printf("How long is your message?
[Code] .....
View 6 Replies
View Related
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
View Related
Sep 30, 2013
So the plan is to create a word search by reading in characters from a file into an array. This is my code so far, nowhere near finished but have encountered a problem already:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ROWS 20
#define COLUMNS 20
int main()
{
[Code]...
My question is to do with the section highlighted in red... I can't really see why it is not printing out my array (wordsearch), it's probably very basic but I have no C experience so am not too confident in what I'm doing.
View 1 Replies
View Related
Feb 26, 2013
is there anyway to read an entire file and print in on screen? file consists of strings and integers!
View 7 Replies
View Related
Feb 1, 2013
I must take an old MFC project in VC++ 6.0 and make changes.
The problem is text size in screen is different from size in print preview.
for example with this font
Code:
CFont f50;
f50.CreateFont(100,0,0,0,FW_BOLD,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,"Frutiger LT Std 45 Light");
And this text
Code:
s=_T("Let's try to calculate the size of this text");
and with MM_LOMETRIC map mode
GetTextExtent() returns me:
On screen: (1595,99)
Ink printer + print preview: (1589,100)
PDFCreator + print preview: (1580,100)
comparing with screen size the height is bigger but lenght is smaller. I don't understand.
I can understand that different printers process the fonts in different way and then to have different lenghts. That's not the problem. The problem is I need to simulate in screen the same behaviour i will have on printer because these texts are being aligned in the document, and I don't want to see that the text si aligned different in text than in paper.
What can I do to render the text on screen with the same size I will have on the printer? Print preview is doing it. Should I change the font parameters? is something related with pixels per inch?
View 4 Replies
View Related
Jul 5, 2013
I have a text file (test.txt) with the following data:
01,05,25,20130728
01,06,25,20130728
01,07,25,20130728
01,08,25,20130728
01,05,25,20130728
01,05,25,20130728
01,05,45,20130728
01,05,65,20130728
01,05,85,20130728
01,05,35,20130728
01,05,25,20130728
01,05,35,20130728
I want to read this to one string called line. So far I have this code:
string line;
ifstream myfile ("/home/Test.txt");
if (myfile.is_open()) {
while (myfile.good()) {
getline (myfile, line);
for (int a = 0; a <= 335; a++) {
cout <<line.at(a);
} }
myfile.close();
}
so far its only printing the first line and then throwing an instance of 'std::out_of_range'
View 2 Replies
View Related
Aug 24, 2013
I can able to get the last line ten chars but i cant get if the last line is null.
here is my code
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
[Code] ....
here with i have enclosed my file where i am pick my last ten chars ...
Attached Files : log.txt (4.8 KB)
View 1 Replies
View Related
Sep 9, 2014
I am trying to automatically(periodically) print screen a custom area of the screen, save it as an image file (the image will have the same format always), and then use OCR to get the text in the image as usable string variables. Is this doable? I was looking into tesseract OCR but I find it a bit unclear.
View 10 Replies
View Related
Sep 23, 2014
I am trying to make a program that will convert a list of binary numbers from a file into decimal and print the decimal to the screen. I have no problem doing the conversion, the problem comes up when our teacher wants the input file in a format as such:
3
10110101
11111111
10101010
The first number is supposed to tell the program how many different 8bit strings it is going to have to convert, and then the following lines are those binary numbers.
I am not very experienced with file inputs, and I know how to open files and read lines in.. The problem is, how to say "ok the first line says 3, so now I have to convert the next 3 lines" . I am assuming it is just a simple loop that I am missing....
View 4 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
Oct 28, 2014
I have code that creates an index file created from a data file of records.
#include <iostream>
#include <fstream>
#include <map>
#include <sstream>
#include <string>
#include <iomanip>
using namespace std;
class Record {
[Code]...
I now need to write a second program that allows the user to enter a command on the Linux command line such as
search 12382 prog5.idx
and returns the information for the record with that key. The code I included for the index file is correct and works properly, but how to write the second program.
Here is the index file created by the first program:
8: blank 0 $ 0.00
12165: Item16 30 $ 7.69
12345: Item06 45 $ 14.20
12382: Item09 62 $ 41.37
12434: Item04 21 $ 17.30
16541: Item12 21 $ 9.99
21212: Itme31 19 $ 8.35
34186: Item25 18 $ 17.75
41742: Item14 55 $ 12.36
The top line is a dummy record, the first number is the size of the file.
View 19 Replies
View Related
Jan 19, 2014
I am working on a wage application with four options which are as follows:
Subtracts an amount from the shop bank account (The account is text file "shop"). You do not need to add the same amount to another account but you should record the transaction with a timestamp in a separate file. The application should prevent the account balance from becoming overdrawn.
List the five most recent transactions to the screen. If there haven’t yet been five transactions then list all of them.
Print the account name, number and current balance to the screen.
Exit the program.
I have completed 1,3 and 4 but I am completely stumped as to how to go about number 2.
#include <limits>
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <ctime>
#include <string>
int read_balance(void);
void write_balance(int balance);
[Code] .....
View 1 Replies
View Related
Dec 8, 2013
How to get this thing to work. All i need to do is ask user to input a name and then it brings out the line from the .txt file containing the information.
For example in my case I'm doing a member search function I'm required to ask user to input the name of the customer and then print out all the details (which consumes 1 text line in the .txt file)
Here is the code, This is the write to text file method (100% working)
Code:
cout << "Customer Name: ";
cin >> name;
// ...
ofstream myfile("customer.txt", ios::app);
[Code] .....
View 3 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 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
Jul 27, 2014
I've been struggling with this for a while, I have to write a function that accepts a word (in my case the word is "the") and file pointer, and counts the number of times the given word appears (case insensitive) within the file associated with the pointer. This means the two words "the" and "THE" should both be counted.
Here is my code:
int WordCount :: countWords(string wrd) {
int counter=0;
string temp = "";
while (getline(*file,temp)) {
for (int i = 0; i < temp.length();i++) {
[Code] ....
This is what I have come up with, but I get an incorrect value. It was suggested to us to consider using the strcpy() or strstr() functions, but I don't know how to use them.
View 6 Replies
View Related