Visual C++ :: Reading And Outputting Files - Sentences And Abbreviations

Mar 26, 2013

I have got an assignment. It is about comparing two files one file has sentences and the other abbreviations. so far i have managed to compare the abbreviations which appear in the sentence and erase punctuation linked to abbreviations.

However I am currently stuck on putting the punctuation back in when outputting the file. I am also stuck with replacing matching words in the sentences with the expanded abbreviations. Not sure which code to show. but sentences and abbreviations are below.

ABBREVIATIONS

Aberd Aberdeen
admin administration
approx approximate
Austral Australia
div division
Capt Captain
Comdr Commander
e east
HQ Head Quarters
m metres
mil million
mt Mount
n north
NATO North Atlantic Treaty Organisation
NSW New South Wales
pop population
s south
sq square
w west

Text file

NATO troops were on exercise in Aberd Capt Jones of the first div told Comdr Frank that his troops were near the E flank of the NATO forces. Complaining about the amount of Admin, Capt Jones radioed the NATO HQ asked for navigation relative to the HQ. The Captain then left.

For example the abbreviation "Aberd" in the sentence above needs to be replaced with Aberdeen from the abbreviations file. I need the last part of the abbreviation not "Aberd Aberdeen" need just "Aberdeen". Hope the info is understandable.

View 6 Replies


ADVERTISEMENT

C++ :: Reading Complete Sentences From A File

Mar 3, 2013

I need to extract full sentences from a file and the save them in a set. I tried getline to get a full line and then removed the characters after the period. This method doesn't work too well if the other half of the sentence is on another line. How should i fix this?

View 8 Replies View Related

Visual C++ :: Enable Writing To And Reading From Files - Unresolved External Symbol

May 13, 2013

Perhaps this can be a very popular error,

Code:

#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <fstream>// enable writing to and reading from files
#include <cstdlib>
#include <time.h>
using namespace std;
class Person {

[Code] .....

Error list:

Code:

Error 1 error LNK2019: unresolved external symbol "void __cdecl saveperson(void)" (?saveperson@@YAXXZ) referenced in function _main H:Cry_DevProgrammingC++Using_class_ in_ c++Using_class_ in_ c++Using_class_ in_ c++.obj
Error 2 error LNK2019: unresolved external symbol "void __cdecl displayperson(void)" (?displayperson@@YAXXZ) referenced in function _main H:Cry_DevProgrammingC++Using_class_ in_ c++Using_class_ in_ c++Using_class_ in_ c++.obj
Error 3 error LNK2019: unresolved external symbol "void __cdecl editperson(void)" (?editperson@@YAXXZ) referenced in function _main H:Cry_DevProgrammingC++Using_class_ in_ c++Using_class_ in_ c++Using_class_ in_ c++.obj
Error 4 error LNK1120: 3 unresolved externals H:Cry_DevProgrammingC++Using_class_ in_ c++DebugUsing_class_ in_ c++.exe 1

What I can do to fit this problem?

View 14 Replies View Related

C++ :: Changing State Names To Abbreviations?

Feb 13, 2014

The purpose of the code is to read in state names, say california and print CA. However, if it was a state with two words, it would read in only the first letter of each. I.E New Hampshire would be NH.

here's my code:
#include <iostream>
#include <iomanip>
#include <cctype>

[Code].....

I am able to get the one word states and tried getting the two word states but it doesnt work.

View 1 Replies View Related

Visual C++ :: Control Structure Outputting Wrong Iterations Via Ints?

Mar 18, 2013

I have this:

Code:
for (chr_min = 0; chr_min <= 24; chr_min += 3) {
strOut = "";
for (ctr_row = 1; ctr_row <=3; ctr_row++) {
switch (ctr_row) {
case 1:
strOut = strOut + Line1.substr(chr_min, 3);

[Code] ....

it is outputting to the shell window, this:

Code:
1
1
1
2
2
3

and that pattern apparently repeats for every iteration that's specified in the outer loop. am I missing something here?

View 14 Replies View Related

C++ :: Files Reading From PDF?

Feb 26, 2013

How do I read a .pdf file using C++? When I try to open it using myfile.open ("example.pdf"); but all I see is some Crazy Symbols. Is there any way to open ?

View 3 Replies View Related

C++ :: Reading In Values From Txt Files

Dec 22, 2014

I cant seem to read stuff in from my students.txt file which contains this

19992195 John Smith 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
20051195 Mark Dobson 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
20063196 Paula O'Reilly 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
20053344 Aoife Cleary 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81

It has something to do with the lines at the bottom of the code. It doesnt cout anything. The program just crashes upon execution. First, it asks me the amount of students i want to handle. I enter '1'. Then it asks me if i want to read in from external file and i enter 'Y'. then the exe just crashes

#include <iostream>
#include <cstddef>
#include <cstdlib>

[Code]......

View 3 Replies View Related

C++ :: Reading And Writing Files?

Feb 20, 2015

I have to write a program that sorts names and grades from a file and output them to another.

For example:

Name: Peter Parker
Exam 1: 95
Exam 2: 90.625
Exam 3: 91.20

Name: Mary Smith
Exam 1: 65
Exam 2: 79.1234
Exam 3: 70.24

Becomes something like this in the output file:

Name: Parker, Peter
Average Score: 92.28
Grade: A

Name: Smith, Mary
Average Score: 71.45
Grade: C

I know I'm supposed to read the whole file, but I'm getting really confused on how to take the name of each student separately without recording Exam 1, 2, and 3. I'll be able to do the average score and grade on my own.

View 2 Replies View Related

C++ :: Reading Records From Files

Jan 28, 2014

Is there a way to indicate how many records exist in a given file? For example, vectors have the vector.size() command to show the number of given elements. Is there a such command for files and records?

View 6 Replies View Related

C++ :: Reading From 2 Files And Merging

Oct 3, 2014

The directions are to write a program that reads sorted integers from two separate files and merge the contents of the file to an output file (third file). The only standard output will be any errors to be reported and a “FINISHED” statement after all items have been processed.

file1.txt
2
4
6
8
10

file2.txt
1
5
11
12
15

Output.txt
1
2
4
5
6
8
10
11
12
15

This is the code I have so far, but it is not working, and I have put the two txt files in the same directory as my .cpp file. It is not working though still. What have I done wrong and how can I fix it to read these integers from the two numbers and merge the contents into a third file?

#include <iostream>
#include <fstream>
using namespace std;
int main() {
int num1;
int num2;
ifstream inputFile;

[Code] ....

View 5 Replies View Related

C/C++ :: Reading From Files And Using Functions?

Mar 24, 2014

My question portion is attached. The code I have written is below.

#define _USE_MATH_DEFINES // for C++
#include <cmath>
#include <iostream>
#include <iomanip>

[Code].....

View 3 Replies View Related

C/C++ :: Reading And Writing Files

Jan 16, 2015

I'm messing around with reading and writing files. The first file creates a small txt file. Simple enough

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
string name;
string desc;

[Code] ....

It does what it should. It creates a text file "items.txt" .... It reads as such:

dagger,a dagger,15,10,0,1,3,1,0,0,0,1,0,0,0,0,0,1

The second file is meant to read the file and place the data back into the variables. This happens, but the data crams itself into the first variable, and the rest of them collect the trash that's in memory.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string name,desc;

[Code ....

I need to get "dagger" into name, "a dagger" into description, and each value with their perspective variable. I'm sure I need some type of "separator". Hopefully I can use the comma. Before it's over, I will have about a hundred items that will need to be read into a class of items.

View 4 Replies View Related

C/C++ :: Reading Numbers From Two Files

Jun 11, 2014

My assignment was to take numbers from two different files, and merge them into a third file in numerical order. I have everything working well, but the output shows the lowest number everytime and i'm not sure why. logical error ....

Sample:
File1 File2 File3
10 12 10
20 25 12
30 37 10
40 49 25
10
37
10
49

Here is my code as well

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main() {
ifstream File1, File2;
ofstream Output;

[Code] ....

View 14 Replies View Related

C++ :: Reading BMP Files Headers

Apr 19, 2013

Code:

struct magic {
char windowsheader[2];
} magicnumbers;
struct bmp {
unsigned int sizeofthefile;
short int applicationspecific1;

[Code] .....

When I run this program, seems like it is working,at least I am sure that it gives the right file size. But if I don't use struct magic and instead use:

Code:
struct bmp {
char windowsheader[2];
unsigned int sizeofthefile;
short int applicationspecific1;
short int applicationspecific2;
//same lines with above
} bitmap_header;

And if I don't use first fread:

Code:

fread(&magicnumbers,sizeof(magicnumbers),1,fp);

Then the values which structure "bmp"'s variables get become wrong. Of course I change the related printf to:

Code:
printf("
windowsheader:%d %d
",bitmap_header.windowsheader[0],bitmap_header.windowsheader[1]);

Why does the problem happen,what is the difference between them?Why do I have to use separate structs?

View 2 Replies View Related

C++ :: Reading FASTA Formatted Files?

Nov 27, 2013

reading fasta formatted files. Usually ppl from computation biology know what that is but for those that are not here is a quick guide :

Fasta formatted file:

Code: >header
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseq
>header1
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseqseq

... so a very simple file format. and what i need to do is to read that into memory (vector of strings) so that header info and seq info is in two different vectors. for that i am using the following function :

Code:

sequence and headers vectors are class variables:

template <typename TStr>
template <typename FS>
void FastaSeq<TStr>::ReadFasta(FS& fs){
string line;
string seq;
while (fs >> line){
if(line.c_str()[0] == '>'){

[code].....

this code does what is suppose to do but it is EXTREMELY slow. it takes me exponentially more time to read the seq in memory then to process it. when compared to c style alternative that reads character by character it takes 13 sec with this function to do the same job that my c function does in 0.03 sec. How to improve upon this function to make it comparably fast (also i am using optimization) ?

View 10 Replies View Related

C :: Reading Files Of Unknown Size

Jan 23, 2013

I want my program to be able to read text files in the format:

number number
number number
number number...

and so on, so there are two columns of values. The problem I'm having is, there are a lot of numbers in the file, and it can vary. The program needs to read the numbers, put one column into one array, and the other in another, perform some operations on it all, and eventually pop out two different arrays. In other words, after I've got these arrays, I don't need them for much longer. I was hoping I could dynamically allocated some arrays to store the numbers and just free them as soon as I'm done with them.

If the file wasn't of such variable size or if it was guaranteed to be under a certain number of variables, I would have used:

Code:

while ( fscanf(input, "%lf %lf
", &col_1[], &col_2[]) == 2 )
{
no_rows++;
}

The problem is I want to allocate "no_rows" as the array size, which I don't have until after I have read the file.

View 9 Replies View Related

C :: Error While Reading Files In Directory

Sep 7, 2014

I use this header dirent.h to get list of files in directory

[URL] .....

I am using code::blocks on windows XP.

Directory "kernels_source" is placed in project's directory where I am running the code.

Code:

#include "include/types.h"
#include "include/gaussian.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

[Code]....

View 10 Replies View Related

C :: Program Reading / Writing Files

Dec 10, 2013

program that I am working on. I want to use fgets() in my program so I could handle multiple words from a text(to be able to handle spaces). I get a weird result when running the program.

Code: #include <stdio.h>
#include <stdlib.h>
//#include "kim.h"
#include <string.h>
[code]....

View 4 Replies View Related

C++ ::  Reading Files Saved On Computer

Jul 20, 2014

I can't seem to get my program to read a file that's saved on my computer. Here's my code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream inputfile;
string name;

[Code] ....

View 6 Replies View Related

C++ :: Reading TXT Files - 0 Unsatisfactory Score

Dec 10, 2013

int main() {
double x, avg, max=0.0, min=100.0,totalsat=0.0, totalunsat=0.0, totalout=0.0;
int invalid=0, outstanding=0, satisfactory=0, unsatisfactory=0, kount=0;

ifstream inFile;
inFile.open("grades.txt");

[Code] ....

When the program tries to open the text file it just scrolls "0 unsatisfactory score" forever. The text file has grades in it I'm trying to sort

63
75
121
72
72
78
67
-9
80 .....

View 1 Replies View Related

C++ :: Vectors And Reading / Writing Files

May 19, 2014

How to write the code for this with the following requirements:

download the text file weblog.txt

This file is an Apache web log taken from the web server for St. Mary's University. When a visitor goes to their web site, the visitor's browser makes a request to the web server to view a web page, which is a file residing on the server. Each time a page is requested by a browser, the web server records information about that request. This weblog.txt holds the details of some of those requests.

Create a non-member function to read each line of the web log file. This function must do error checking to ensure that the file is opened successfully, otherwise it must provide a message like "file not available" to the user.

Each line should then be stored in a vector such that the first element of the vector is the first line of the web log file. Because each element will hold an entire line from the file, the vector should be declared as a vector of strings.

Note: You must declare the vector in a function.

Create another non-member function to sort the contents of the vector. Make sure to pass the vector by reference or your sort will disappear when the function ends! Use the sort function with #include <algorithm> to do the sort; you do not have to write your own sort algorithm.

Create one more non-member function to write the contents of the vector to a file. Each element should be on its own line in the new file. The contents of the new file should look like the original input file once your program completes, but in sorted order.

Create a main function that calls all of your non-member functions.

View 2 Replies View Related

C/C++ :: Reading And Writing In Binary Files?

Jun 5, 2014

why I'm giving "Access violation reading location 0x336827B8" and also I was able to read my data but it's giving me weird stuff. I want to write the sorted grades and the average in a new disk file. so here's my code so far here's my code

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int avg(int sum, int size);
void swap(int *, int *);

[code]....

View 5 Replies View Related

C++ :: Reading Large Number Of Binary Files

Apr 14, 2014

Windows 7, 64 bits, Visual Studio 10.

I have a problem to read a large number of binary files, process them and store them under a new name. The program and routines go very well for 505 files. After reading 506 files, the program now refuses to read the next file. I have 16 Gb of memory and tried to close all other programs and restart the PC. it always stops after 506 files (512 files would be more understanding in a way...).

Here is my code. I have tried many things without success. This is only part of the loop that stops. The if test if (myfile.is_open() returns false by some reason. I can start the process again starting with the file that does not open and then it stops again after 506 files.

char * tfiBlock;
ifstream myfile (OrigFilename, ios::in|ios::binary|ios::ate);
if (myfile.is_open()) {
int lengde = myfile.tellg();
tfiBlock = new char [lengde];
//static char memblock [size];

[Code] .....

Clean up procedure:
delete[] tfiBlock;

Are there any limits to how many files that can be opened, or is it maybe someting to be set in the compiler?

View 5 Replies View Related

C++ :: Reading Multiple Text Files In Program

May 31, 2013

I want to know how to read multiple text files in this program... I have 5 text files(order1,order2,...order5).

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<windows.h>
using namespace std;
class{

[Code] ....

View 3 Replies View Related

C++ :: Reading Source Code From Uncompleted Files?

Jun 9, 2013

I know it sounds strange but I've seen things that have files which contain source code (usually in something in Python or such) and how this is read on run-time?

View 1 Replies View Related

C++ :: Writing / Reading String Objects To / From Files

Jul 7, 2013

I am using the code below to write a single instance of object "Employee" to a file in Binary mode. The write part seems to work fine, however when I try to read the single employee object from the file into memory I get a double free or corruption error.

I think this has to do with the fact that I am using a string data member in the Employee class but I don't understand what is going wrong. I have read that strings can vary in length and use dynamic memory allocation but if I write a single employee object to a file with data member 'name' equal to "John", it should be the exact same size when I read it back in right?

The code below works with no issues when I omit the string data member. Why is that? Where is the memory for the string object being "double released" when I read the employee object back into memory from the file?

I am using Linux Mint 15, Eclipse June and GCC 4.7.3 with the -std=c++11 option.

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

[Code].....

View 3 Replies View Related







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