C++ :: Read Story From Input File / Separate Words And Output Lines On Which The Word Occurs

Feb 21, 2014

I have program that is supposed to read in a story from an input file and separate the words and output the lines on which the word occurs. It needs to read in another input file that has a list of words (1 per line) to ignore. i.e. skip them when running through the story. This is what I have so far, I've changed multiple things trying to get it running....

#include<iostream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<string>
#include"split.h"

[Code] .....

View 1 Replies


ADVERTISEMENT

C :: Read In N / Then N Words And Check To See If First Word Is Repeated

Sep 23, 2013

Read in n, then n lastnames, and check to see if the first in the list is ever repeated again.Here's what I have so far:

Code:

#include <stdio.h>
#include <stdlib.h>
int strcmp(char *w1, char *w2);
int main() {
int j, n;
char string1[30], string2[30];
}

[code]....

I see the problem is that it lies within n amount of string that I am not going through every string to compare to the first one.How will do compare every string to the first one?

Current output:
3
alex
alex
alex
Not repeated

3
alex
ash
peter
Not repeated

View 2 Replies View Related

C++ :: Read Input File (XML) And Generate Output File

Mar 25, 2013

I have code that reads an input file and generates an output file .For reading the input file we have a xml file.If there is an error while reading or writing the output file the an errored file is generated. But in the errrored file the fields are not coming as in accordance with the reader xml . They are coming randomly . In the module for reading and writing the errored file list is being used . What should be done to write in the errored file as the reader xml fields.

View 1 Replies View Related

C++ :: Read Input File (XML) And Generate Output File

Mar 25, 2013

I have code that reads an input file and generates an output file .For reading the input file we have a xml file.If there is an error while reading or writing the output file the an errored file is generated. But in the errrored file the fields are not coming as in accordance with the reader xml .they are coming randomly . In the module for reading and writing the errored file list is being used . What should be done to write in the errored file as the reader xml fields.

View 1 Replies View Related

C++ :: Print Out Number Of Words And Lines In A File

Jan 29, 2012

Write a program that prompts the user for the name of a file. Then it opens the file, and counts the number of words and lines in the file, and prints out those counts.

I think I possibly could somehow use a counter to increment using getLIne() until getLine() returns NULL, but the problem is, I'm worried if I try that, a file that looks like this:

Bla bla bla bla bla lkfdljkfaklafdskjladsjkdfkjlkdfjdfshafdsjkjrerjkkjfaddjkfsafkjdjakdfsjkasfjkjkfdskjldfjkfjkdjfkdsakdjfkjfdkjdfskjfdsk
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjdfkerea
blkjadkjlfdskjldfkjlfdkjfdjkdfsjkldfskljfksfdljfd

Only register four lines and not get the one after the fourth line.

So I was thinking of something like

Code:
#include <iostream>
#include<ifstream>
#include<cstring>
#include<string>
#include<vector>
#include <cstdlib>
using namespace std;
iostream keyboard;
ifstream file;
iostream cin;

[Code] .....

Did I do that right? Will that count the number of words and number of lines correctly?

View 14 Replies View Related

C :: Working With File And Counting Characters / Words And Lines

Dec 17, 2013

I have to write a program (on linux) which will count character, words and lines like wc linux command. I'm trying to write this for last 3 days... First part of app I did and it works fine - command line options to choose. Then I've got a function read_file which I have to use to read a file. One of the options is to get the file name from user and if user will not type any name then the standard file is ubuntu dict file /usr/share/dict/words, this is not working as well...

Counting characters and lines is working fine but because I don't know how to get text from read_file wrote code to read file interior this functions. Words counting is working partly - everything is fine until there are two or more spaces, tabs one after another then counts extra words. Finally I need child processes in words and lines counting functions. Parent process should waits for all childs to finish and should be pipes to submit character counts back to parent process. How to do all this things with processes...

Code:

#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
/*size of character buffer to read in a file. */
#define BUFFSIZE 1000000

[code]....

View 2 Replies View Related

Visual C++ :: Read Some Text And Output Without Displaying Repeating Words

Sep 8, 2014

I have been given an assignment to make a code to read some text nd display all the words nd the number of times they appear in another file or as output without displaying the repeating words. I made the code but its not giving any output.

#include<iostream>
#include<conio.h>
#include<fstream>
#include<string>
using namespace std;
void read(string);
string x,z,w;

[Code] ....

View 3 Replies View Related

C++ :: Count Number Of Words And Lines Then Print All Words

Dec 20, 2013

I have written below program to count number of words and lines and print the all the words.

#include <iostream>
using namespace std;
#include<fstream>
#include<string.h>
int main() {
ofstream outfile;

[Code] .....

Its compiling fine but when executed its displaying I infinite times...

View 3 Replies View Related

C :: Count Lines In Input And Display Output In Terminal When Program Executed After Compilation

Feb 4, 2013

Code:

#include <stdio.h>
main() {
int c, n1;
n1 = 0;
while ((c = getchar()) != EOF)
if (c == '')
++n1;
printf("%d", n1);
}

I have a more complicated program I'm wishing to have display the output, however, to save some time I'm using an example of a shorter version. count the lines in input and display the output in terminal when ./program is executed after compilation. To count and compute lines, words and within arrays.

View 4 Replies View Related

C++ :: Read From A File And Store Information In Separate Variables?

Dec 8, 2014

So I have to read from a file, and store the information in separate variables. My problem is that for some of the information I need multiple words, and for others I don't, so I cant simply store 1 word into a variable and store the next in another in so on. To demonstrate what I mean let me give an example.

Dog Cat Blue Bird Snake White Horse

I am able to store "Dog","Cat","Blue","Bird"...etc in variables but I don't know how to make it so I can store "Dog" in one variable, "Cat" in a second variable. and "Blue Bird" in a third variable. "Snake" would be the 4th and "White Horse" would be the fifth. How can I read a file and manipulate the pointer to grab what I need?

View 2 Replies View Related

C/C++ :: Showing Separate Lines For Objects?

Mar 31, 2014

#include<iostream>
#include<string>
using namespace std;
//Constructors for class.
class CollegeCourse {
private:
int courseNum;

[Code] ....

When I debug my program, the objects is showing up on one line bunched up together. I also want to be able to enter data after each object of the classes.

The details of my project is as follows:

Inheritance in C++ means you can create classes that derive their attributes from existing Classes, in other words, a newly created class can absorb all the data fields and functions of a class already being used. When one class is derived from another, the original class is the parent class, base class, or sometimes called the parent class. The derived class is a child class, or sometimes called the subclass.

Inheritance is central to Object Oriented Programming. The advantages of inheritance are it allows the code to be reused as many times as needed. Inheritance also saves time and effort as the main code need not be written again.

Create a C++ program using Visual program that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates and uses objects of each class.

View 1 Replies View Related

C/C++ :: How To Print Random Number Asterisks On Two Separate Lines

Apr 20, 2015

Im trying to figure out how to print a random number of asterisks on two separate lines at the same time. So every time you press a key it prints a different amount of random number of integers between1 and 10 until one of the lines reaches 70. I have the code to do one line but can't figure out how to do two at once.

#include <stdio.h>
#include <time.h>
#define MINR 1
#define MAXR 70
#define MINM 1
#define MAXM 10
int main (void)

[Code]...

View 2 Replies View Related

C++ :: Read Only Certain Lines From CSV File

Oct 21, 2014

I am trying to read lines from a CSV file and put the values into vectors. The CSV contains a large amount of data and I would like the program to only read certain lines from the CSV into the vectors. An example of the data is below. In my code the user inputs a secid. I would then like the code to only read lines from the csv where the secid matches what the user inputs. The secid's are also not in order so I can't just use a while loop.

My current code is below the data.

secideffect_datecusip ticker
10131014MAY19972313510 AMZN
10131008MAY19982313510 AMZN
10131028NOV20002313510 AMZN
10131023JUL20012313510 AMZN
10196601JAN199663858510 NB
10196601OCT199806605F10 BAC

ifstream infile3("filepath.csv");
if (!infile3) {
cerr << "Couldn't open file!"<<endl;
return 1;

[Code] .....

View 1 Replies View Related

C++ :: Read Certain Lines From A File?

Aug 22, 2014

I want to read certain lines from a file. Let say if the line contains word "makes", the line will be loaded on the screen.how to modify this code.

// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;

[Code] ....

View 1 Replies View Related

C++ :: Read And Rewrite Lines In File

Jan 2, 2015

My task is to write a function for borrowing books form library called borrow(name,surname, student_id, book_id), which will connect information of borrowed book's ID and student's information in the file.

File looks like this:

John Jackson 45 0
Michael Gregory 34 56
Ann Cawitch 23 0
Chris Lamb 34 50
...

First two words are name and surname of students. First number represents student's ID and second one represents ID of book. If ID of book is 0, it means that student hasn't borrowed book yet, so he can borrow some book. If ID of book is not 0, it means that student can't borrow a book until he returns the old one. So, when student borrows book, ID of book in file should change from zero to some number

This is my code:

void borrow(string name, string surname, int student_id,int book_id ) {
string a;
string b;
int c=0;
int d;
fstream f2;
f2.open("students.txt", ios::out |ios::in);

[Code] ....

Whenever I call function (for example borrow(John, Jackson,45,15)), I get answer "Student isn't sign up library."

Am I on a right path? How to make this code to work?

View 4 Replies View Related

C :: Segmentation Fault When Try To Read In The Lines Of File

Oct 21, 2013

I have to txt files, and want them to read into an array line by line and after then a split the lines with delimeters, at the first file I use ";", at the second file I want to split the lines to single words by spaces. My aim is to get the first word from the first file and compare with all the words from the other file, to check is there any matches.

My problem is, that at the first file works everything fine, and I want to do the with the second file, but after reading the lines into lines_input[], I check the an empty = null line, I get segmentation fault.

You can see the code below:

Code:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>

//Change the

[Code] .....

View 1 Replies View Related

C++ :: Read A File And Break It Into Lines And Characters?

Jan 31, 2014

I am writing a code to read a file and break it into lines and characters but I am getting an error do not know the reason for it though.

here is my code

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

[Code].....

The first line is executing properly but when it goes to the second line I get an error "the program has stopped working"

View 1 Replies View Related

C# :: How To Read Extra Lines Of Text File

Jan 12, 2014

private void open(object sender, EventArgs e) {
OpenFileDialog openDialog = new OpenFileDialog();
if (openDialog.ShowDialog() == DialogResult.OK) {
string[] lines = File.ReadAllLines(openDialog.FileName);
int k = 0;
while (k < lines.Length)

[Code] ....

So in this code, the user basically opens a text file from the dialog. Then the file gets read on all the lines and gets stored in an array. Now the reason I did this is because there are more fields of text boxes I have to fill in after I fill in the table (6x3). I'm getting an out of bounds error however.

19
19
19
0
95
0
0
0
0
5
0
0
5
1
0
0
51
1
110
Warrior

This is a sample text file that is being used. As you can see all the lines from start up until (excluding "110") will be used in the table. Now I want to read the last lines in this text file and put it in another text box. How do I do that?

View 2 Replies View Related

C :: List Of Words That Need To Be Read In From A File And Then Sorted

Apr 4, 2013

I'm given a list of words that need to be read in from a file and then sorted. I was given a certain way to do it .

Code:
#include <stdio.h>
#define MAX 100
void print_ar(char x[][MAX], int size);
int strcomp(char x[], char y[]);
int strlength(char x[]);
void selection_sort(char c[][MAX], int size);
void strcopy(char x[], char y[]);

[Code] ...

Here are some words from the list

school
aibohphobia
lists
alula
bake
cammac
civic

I cannot figure out what is wrong at the moment. .

View 3 Replies View Related

C :: How To Initialize Variable Word In Separate Statement From Its Declaration

Aug 7, 2013

I wrote the following program to initialize a string after the variables is declared, but it isn't working. A warning is given by the compiler, and the execution of the program shows a strange string. How do I initialize variable word in a separate statement from its declaration?

Code:

#include <stdio.h>
int main( void )
{
char word[20];
*word = "Hello";

printf( "The string is %s.
", word );
return 0;
}

View 3 Replies View Related

C :: Program Count Number Of Lines Of Read Text File

Jan 25, 2013

I have a .txt file that contains, together with a few characters, columns of values that I want to save in different files like is written in the program (file 1, file2, file3 - a with x, b with y, c with z). The pattern of the source text file is like this:

known_vector frame1 151 65 0 frame2 151.000763 64.538582 0.563737
known_vector frame1 152 65 0 frame2 152.000702 64.542488 0.560822
known_vector frame1 153 65 0 frame2 153.000671 64.546150 0.558089

Until now I could manage to split the files, but the output gives me only zeros. First the program count the number of lines of the read text file, then it should display the desired columns of double values in three other .txt files.I've got for the three .txt files columns like this:

0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000

View 2 Replies View Related

C :: How To Input Lines At A Specific Area In File

Feb 15, 2013

how can i input lines at a specific area in my file. please provide code

View 3 Replies View Related

C++ :: Read In Lines From A File / Store In Variables Then Construct Instances Of Class

Aug 22, 2013

I can't get my code to compile, i need to read in lines from a file and store them in variables. Then i have to construct instances of my class for how many lines there are in the file and take those variables into them.

I'm getting this error :

"a2.cpp:40: error: cannot convert `Employee' to `Employee*' in assignment"

#include<iostream>
#include<string>
#include<fstream>
void displayInfo();
using namespace std;
class Employee{

[Code] .....

View 1 Replies View Related

C++ :: How To Read A Specific Word From A File

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

C :: Read Text From A File And Show What Words Occur How Many Times

Apr 21, 2013

I'm trying to make program that will read text from a file and show what words occur how many times. I'm trying to make it so that if a new string comes, it saves it into wlist[], and counts 1 to wcount[]. If the same word is there, it will just add 1 to wcount[]. The program will end when it gets to the end of a file.

I don't know the reason, but I can't get strcmp and strcpy to work. I had to put a pointer in curword, just to make it compile.

Code:
#include <stdio.h>
#include <string.h>
#define LIST_MAX 100
#define WORD_MAX 20
int main(){

[Code] ....

View 6 Replies View Related

C++ :: Input And Output Files - Names Should Be Read From Command Line

Aug 3, 2014

I am having an issue with the statement "Both the input and output files' names should be read from the command line." I don't understand what this means or what I need to do.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved