C++ :: Merge Two Sorted Files Failing

Oct 7, 2013

I have to merge two sorted files. Algotrithm that i'm using is below, but it reads not all the numbers in the files, and stops, even the files contain the same number of elements. What is wrong, I can't understand.

ifstream f1("E:desc1.txt");
ifstream f2("E:desc2.txt");
ofstream f("E:desc.txt");
cout <<endl<< "Nuerele sortate: " <<endl;
int n1, n2;
f1 >> n1;
f2 >> n2;

[code]...

desc1.txt is:

99 97 95 93 91 89

and desc2.txt is:

100 98 96 94 92 90

and I'm getting this:

100 99 98 97 96 95 94 93 92

View 1 Replies


ADVERTISEMENT

C :: Function That Merge Content Of Two Sorted Arrays Of Double Type Values

Nov 4, 2013

I need to write a function that will merge the content of two sorted arrays of type double values. The function should not assume that both its input parameter arrays are the same length.

Here is my program so far - I know there is alot of errors and mistakes:

Code:

#include<stdio.h>
void merge(int firstArray[],int secondArray[],int size) {
int mergedArray[size],i=0,j=0,k=0;
while(i<size||j<size) {
if(i==size) {

[Code]...

View 2 Replies View Related

C++ :: How To Merge Binary Files

Jan 5, 2013

I am attempting to merge binary files. However, this is to no avail. The program keeps segfaulting. I want to merge the buffers the files are stored in and then write the new one to disk. Anyway, here is my code.

Main.cpp:

#include "getsize.h"
long lSize;
char * buffer;
size_t result;
FILE * pFile;
FILE * pFile2;
FILE * pFile3;
void read1() {
pFile = fopen ( "uTorrent.exe", "rb");

[Code] ....

View 19 Replies View Related

C++ :: Read Two Files And Merge Alphabetically

May 11, 2014

I'm trying to finish this project which is supposed to read two files, and merge them alphabetically. I've written this code, and it compiles. But it isn't actually doing anything??The console opens and closes immediately upon running.

Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
#define hisFamily "The Adopted.txt" //His family
#define herFamily "The Originals.txt" //Her family
#define ourFamily "The Big Picture.txt" //Our family

[Code] ....

View 7 Replies View Related

C/C++ :: Program That Can Merge Files From Command Line In Li

Sep 22, 2014

I have written a C++ program that is supposed to open two text files (prog2a.dat and prog2b.dat) and write the contents of a specified range of lines to an output file (outfile.dat). I wrote a program that based on the example we were given (to take lines 5-15 from the first file and lines 4-12 of the second file and merge them into the output file) works perfectly. However, after asking my professor for some clarification on another part of the assignment, I found out I have not done this correctly. I have the code written so that it will always output the range of lines I mentioned earlier, but the program is actually supposed to allow the user to merge the files from the command line using whatever range they want by typing in the following command:

prog2 in1 5-15 in2 4-12 outfile

But I'm not sure how to tweak my current program to allow this to be done.

Here is the code that I have written, keep in mind that this works properly for the way it is written, but not how it is supposed to work for the purposes of the command line (hopefully that makes sense):

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main() {
// Create output file
std::ofstream outFile("outfile.dat", ios::out);

[Code] .....

Is there any simple way to make this work as I described using the command line? Also, I am supposed to break this up into three files, a header file, the program file, and a test file (the test file contains main() and should close the 3 open files and display any error messages), but I'm getting really confused as to what should go in the header file. I know the header file should contain class definitions and constructors, but don't really know how to make that work for this specific program?

View 13 Replies View Related

C++ :: Program To Merge Numbers In Two Files And Write Results To Third File

Apr 9, 2013

I need to write a program that merges the numbers in two files and writes the results to a third file. The program reads input from two different files and writes the output to a third file. Each input file contains a list of integers in ascending order. After the program is executed, the output file contains the numbers from the two input files in one longer list, also in ascending order. Your program should define a function with three arguments: one for each of the two input file streams and one for the output file stream. The input files should be named numbers1.txt and numbers2.txt, and the output file should be named output.txt.

View 1 Replies View Related

C++ :: Binary Tree Heap Destructor Failing?

Feb 5, 2014

I get a runtime error when I add a destructor to my code.

Code:
#include <iostream>
#include <array>
using namespace std;
struct nodes { int* elements; };
class heap

[code]....

View 14 Replies View Related

C :: Passing String To Function (strtoull) Failing

Sep 30, 2013

I have a code in which I am passing string "5368709120" to function strtoull() and it should had returned me number 5368709120 but instead it returns me 1073741824 which is incorrect.

What may be the possible cause of this and how to rectify it?

Code:
typedef unsigned long long
ULL_Type;
char *quotaStr = "5368709120";
ULL_Type quota;
quota = strtoull(quotaStr, NULL, 10);

View 3 Replies View Related

C++ ::  OfStream In Vector Failing To Open File

Feb 20, 2015

I'm trying to move a dictionary into a group of bite-sized files based off of the length of the strings in each file (I'm ignoring strings of length 1 for obvious reasons). Since I don't know what the longest word is (and I'm not going to look for it), and I don't want redundant files, I decided to use a vector of output file streams that I would put all the words into, but I can't get the file to open.

I took a look at it and found the failbit is 1, but the badbit is 0, so apparently it's a logic error on opening the stream [URL] .... I looked online and decided to try using pointers, but that didn't work either, so now I'm asking what the problem might be, because I can't think of any reason why it isn't working.

void createDictionary() {
//declare variables
string dictionaryName;//name of dictionary file
ifstream dictionaryIn;//file of original dictionary
vector<shared_ptr<ofstream>> dictionaryOut;//files where dictionary will be put based off of word length
string word;//input from the dictionary file
vector<int> lengths;//vector containing available lengths and their locations
unsigned long long counter = 0;

[Code] ....

View 2 Replies View Related

C++ :: Memento Pattern Failing Because Of Pointer Data Members

May 24, 2014

All the undos and redos were working fine until the pointer data members came into the picture. The problem is that the values pointed to changed, but the pointers themselves did not. So restoring gives the same pointers but they still point to the new values. I think the solution is that the classes that are the pointer data members themselves need their own Mementos (which would be a lot of work because there are many data member pointers in my program). Is that the only approach?

Here is a sample code to show what I'm talking about. You can compile and run the program to see the problem it has restoring values of pointer data members:

#include <iostream>
#include <string>
#include <memory>
#include <vector>
#include <list>
#include <cstdlib>
#include <ctime>
class FoodHistory {

[Code] ....

View 2 Replies View Related

C++ :: Why Is Basic Battle System Failing (no Compile Errors)

Aug 4, 2014

Here's the source code from "battle.h" (which should probably be renamed to "animal.h")

Do you think I made my errors here or in one of the many other headers or cpp?

#include "Identity.h"
#include "stdafx.h"
#ifndef battle_h
#define battle_h
int numbers1 = rand() % 5;
int numbers2 = rand() % 7;
int numbers3 = rand() % 9;
int numbers4 = rand() % 11;

[code].....

View 8 Replies View Related

Visual C++ :: CryptUnprotectData Failing When Code Compiled On Windows 7?

Sep 24, 2012

I have a C++ code that reads the database password from the registry and decrypts it using CryptUnprotectData. We have to deploy this application on a Windows 7 machine.

When I compile my code on Windows XP and run it on the test Windows 7 machine, it works absolutely fine. When I compile the same code on my laptop having Windows 7 and run it on the test Windows 7 machine, CryptUnprotectData fails with GetLastError() return '87'. If I run this application on my own laptop with Windows 7 on it, it again works fine probably because my laptop has a lot of things installed including Visual Studio and all the service packs etc.

I believe I have missed out installing some dependency on the test Windows 7 machine but I am unable to figure out what is that. What is it that's making the Windows XP compiled code running fine on the test machine and not the code that's compiled on Windows 7.

Here is the call to CryptUnprotectData in the code:

if (CryptUnprotectData(
&cipherText,
NULL,
NULL, // Optional entropy
NULL, // Reserved
NULL, // Optional PromptStruct
CRYPTPROTECT_UI_FORBIDDEN,
&plainText))

[code]....

View 10 Replies View Related

C++ :: Implement Member Functions Of Class Function - Failing To Get Input

Aug 17, 2013

I am supposed to implement the member functions of class Person.

class Person {
public:
Person();
Person(string pname, int page);
void get_name() const;
void get_age() const;

[Code] ....

The code I wrote is below. Where I am struggling is the program does not allow me to input age. Therefore, I cannot test if my temp for age works. It automatically defaults to 0 because it hasn't taken input. Here is my code:

// Program Title: Person function
// Program Description: The program prompts the user for first and last name and age.
// It then prints the output that was provided by the user.

#include<iostream>
#include<string>
using namespace std;
class Person {

[Code] .....

View 13 Replies View Related

C :: File Containing Sorted Numbers

Mar 6, 2015

suppose you we given a file containing sorted numbers

ie
1
2
4
6
7
9
10
12
14

and you needed to inset the number 11 into the file and keep it sorted.

View 8 Replies View Related

C :: Sorted Linked List

Apr 2, 2013

I been ask to create a sorted linked list module, and to test each function with 1 unit, 2 +.so i wrote my addtofront function( we have to use the same as the teacher)

Code:

struct MyList{
char * name;
Sorted * AddmyChar;
struct MyList * next;
}

[code]....

but i cant seem to test it because it always display a seg fault.... i dont know what i did wrong....how do i call this function in main to display a string i want?

View 9 Replies View Related

C/C++ :: Mode Of Sorted Array?

Sep 14, 2014

I've been working to make program to find the mode of sorted array. But the program didn't return the results correctly. Here is the code:

#include <iostream>
using namespace std;
int main () {
cout<<"Enter the size"<<endl;
int size;
cin>>size;
int data [size];

[code]....

View 14 Replies View Related

C++ :: Struct - Getting Grades Of The File Sorted

Jul 21, 2014

My code has no errors. I'm just having problems with getting the grades of the file sorted. grades is not a struct, but is a int inside struct School. Below is what I;m having problems with(this is just the code I started working with,I made a few changes but it didn't work,I have no clue)

void selectionSortG() {
Students min;
int key;
for (int i = 0; i < size; i++){
min = student[i];
key = i;
for (int k = i; k < size; k++)

[Code] ....

View 2 Replies View Related

C++ :: Parallel Scan Of Sorted Sequences?

Feb 4, 2015

I need to take an unknown amount of sorted files and then output any number that is in at least half of them... I know I need to read in the files to a vector and then iterate through them all at the same time looking at the lowest number first and so on. But I am stuck at the point of taking an unknown amount of files and putting them in a container.

This is what I have so far but the vector isn't working and I think I should be putting each file into its own vector.

string get_file(string filename)
{
ifstream in(filename);
if (in)

[Code]....

View 3 Replies View Related

C/C++ :: Find Mode Of Sorted Array

Sep 14, 2014

I've been working on my program to find mode of sorted array. But the program didn't return the res

#include <iostream>
using namespace std;
int main () {
cout<<"Enter the size"<<endl;
int size;
cin>>size;
int data [size];

[Code] ....

View 1 Replies View Related

C++ :: Remove Duplicated From Sorted Vector

Dec 1, 2014

I have vector pair like below, it is sorted but I want to remove duplicate values: The vector is like below:

std::vector<std:air<std::string,double>> fileWeight;

Here is what in vector:

scene1.jpg 0.4
scene2.png 0.4
scene3.jpg 2.3
scene4.jpg 4.1

The highlighted top 2 are duplciated. How can I remove duplciated like this where I have to check whole pair?

View 9 Replies View Related

C :: Sorted List - Why Value Of Void Pointer Change

Feb 16, 2014

I have a the following in a header file.

Code:

struct SortedList{
void * data;
struct SortedList * next;
struct SortedList * previous;
int (*compareFunc)(void *, void *);
void (*destructor)(void *);

[Code] ....

In a .c file, I implemented the SLCreate function.

Code:
SortedListPtr SLCreate(CompareFuncT cf, DestructFuncT df){
struct SortedList item;
item.data = NULL;
item.next = (struct SortedList *) malloc(sizeof(struct SortedList));

[Code] ....

In main.c, I try to do the following:

Code:
SortedListPtr list = SLCreate(&compareInts, &destroy);

A bunch other code that does not alter list or it's contents at all.

struct SortedList item = (*list);
void * data = item.data;
if (data != NULL) {
printf(Why did data become not null???
"); }

How come my variable data became not null anymore when I haven't altered it at all....

View 2 Replies View Related

C :: Sorted Linked List - Crashes On Malloc

Sep 29, 2013

So I've been working on a sorted linked list homework assessment and I've been stuck on a problem for a while now. Below is my code for inserting a new object into the linked list, for some reason it keeps crashing whenever I try to malloc temp. (between the "checkpoint" and "after malloc" printf statements) .

Code:

int SLInsert(SortedListPtr list, void *newObj){
SortedListPtr curr = list;
SortedListPtr temp = NULL;
if(list->obj == NULL) /*if the list is empty insert obj into the first node*/ {
list->obj = newObj;
free(temp);

[Code] ....

View 13 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++ :: Output Data From Two Sorted Arrays Into One File?

Apr 7, 2013

I am trying to output data from two sorted arrays into one file(which should also be sorted). The program works for most of the data, but after it reaches a certain record begins outputting garbage. I'm sure part of the problem is that I don't know what to include in my while loop that outputs to the file.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code]....

View 4 Replies View Related

C/C++ :: Adding Linked List In Sorted Order

Sep 22, 2014

I am currently trying to add to a linked list in sorted order but I have reached an impasse. I can get it to add in sorted order if it belongs in the beginning or second in the list. If i were to type in 9 then 4 i would get 49, but if i type in 5 it changes it to 559. I'm just at a loss and need some sort of direction.

#include "singly_linked_list.h"
#include <iostream>
using namespace std;
void add_node(node*& head_ptr, const int& payload){
if (head_ptr == nullptr) {
node* my_node = new node();
my_node->data = payload;

[Code]...

View 2 Replies View Related

C++ :: How To Pass Array To Function And Return It As Sorted Vector

Sep 17, 2014

How to pass my array to the function and return it as a sorted vector. I'm kind of lost with the functions part.

Problem: Write a program that performs a sorting routine as discussed in class. Create an array of 10 integers (e.g., 63, 42, 27, 111, 55, 14, 66, 9, 75, 87). Pass this array to a separate function that sorts the integers and returns a vector containing the sorted integers. Use either the SELECTIONSORT algorithm or the INSERTIONSORT.

Code so far:
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iomanip>

[Code]...

View 2 Replies View Related







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