When i try to read it back from fstream again there are some symbols (binary obviously). How can i get my values back? I want to read those symbols and in a way to convert them to my old width and height values.
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 *);
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
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?
I am trying to understand what techiques can be used to sort really huge files (larger than available memory). I did some googling and came across one technique.
1. Are there any better ways to get this done?
2. Is there some tweaking that can be done to make this itself better?
Large enough so that you get a lot of records, but small enough such that it will comfortably fit into memory
3. How do you decide on this value? Consider, memory is 4 GB and currently about 2GB is consumed, and file to sort is 10GB in size. (Consumed memory could of course change dynamically during execution - consumed more/less by other apps.)
I have created a program that first sorts a series of numbers that are input dynamically then an option is given to either use a sequential search or a Binary search. my sequential search works fine but the merge sort coupled with the binary search has a small bug that I just can't seem to figure how to eliminate. I first used my own merge sort but it was really in efficient so a I took a more efficient example and incorporated it in my program but I cant seem to get rid of this bug I'm dealing with. and it seems to be causing a further problem with the Binary seach.
Code: #include <iostream> #include <cmath> using namespace std; const int N = 10;
The Problem You are part of a company writing a spreadsheet program. As you know, spreadsheets can be sorted on any column. You're part of the project is to write one binary tree function to sort the data [Hint: use different fields when inserting nodes in the tree.] and a second function to list it in either an ascending or descending sequence. [Note: Each of these functions may actually need to be a set of related functions.]
For sample data you will have a disk file containing information about Shakespeare's plays. Your first function should create a tree based on the sort selected by the user and the second function to display the data in the sequence selected by the user. Regardless of the column being sorted, data in individual records always be displayed in the same line of the output.
Input : Each record will contain the following information: First Performed 9 characters Printed 5 characters Title 26 characters Type 7 characters
Output : Tabular output should be aligned in columns with two spaces between each. All columns should have headings. It should be sorted on the column specified by the user.
Example (This sample data provided so you can test your program.) If the data is:
1595-96 1600 A Midsummer Night's Dream Comedy 1594-95 1623 Two Gentlemen of Verona Comedy 1596-97 1623 King John History 1597-98 1598 Henry IV, Part 1 History 1611-12 1623 The Tempest Comedy 1602-03 1623 All's Well That Ends Well Comedy
[Code]...
Source: [URL]...
Possible outputs are
1 - for a sort by title: First Performed Printed Title Type --------- ------- -------------------------- ------- 1595-96 1600 A Midsummer Night's Dream Comedy 1602-03 1623 All's Well That Ends Well Comedy 1606-07 1623 Antony and Cleopatra Tragedy 1599-1600 1623 As You Like It Comedy
[Code]....
2 - for a sort by first performed: First Performed Printed Title Type --------- ------- -------------------------- ------- 1590-91 1594? Henry VI, Part 2 History 1590-91 1594? Henry VI, Part 3 History 1591-92 1623 Henry VI, Part 1 History 1592-93 1623 Comedy of Errors Comedy 1592-93 1597 Richard III History
This program I'm working on accepts an array size from the user, prompts the user to store that many integers, sorts them from smallest to largest, and then searches for duplicates with a simple for loop. The ultimate goal of the assignment was to display duplicates in an array, and the rest of the functions are just how I decided to reach that goal.
Anyway, my program crashes if I choose an array size larger than 7. It sorts and displays duplicates perfectly with 7 or fewer arguments.
The exact moment it crashes is after I enter the final value it prompts me for, so it appears my inputsize() function and my inputarray() function are working, and the error may be in the arrsort() function. Code is below:
Code: #include <stdio.h> int funcinputsize(int); void funcinputarray(int [], int size); void funcarrsort(int [], int size); void funcdupe(int [], int size);
I'm trying read a binary file. A binary files is continued with bytes(ascci characters). and the 1st position is the position 0(zero).
I'm trying read just some values from ICO file:
- the 3rd value is in 4th-1 position(number of icons); (See the table: [URL] .... ) - the with is the (numberoficons*16) + 4 (the 16 is the Entries structure size) position; - the height is the (numberoficons*16) + 4 + 4 (the 16 is the Entries structure size) position.
now see the code:
int iconwidth; int iconheight; int iconcount; FILE *iconfile = fopen(filename.c_str(), "rb");//open the file fseek(iconfile,4-1,SEEK_SET); //put the file in position 6(the position starts from 0) fread(&iconcount,sizeof(char),2,iconfile);//get 2 blocks with char size(2 bytes).. i'm getting the number of icons
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.
HelI have been tasked with creating a program which (1) takes in integer values from a user (until the user enters -1) and inputs these values into a linked list. This (2)original list is then to be printed out. The program then uses the algorithm "bubble sort" to (3)order the list in descending order before finally printing it out again.
I have managed to do this but I kind of cheated since I do not quite understand how to manipulate a linked list. What did was I took the values in the linked list and transferred them into an array and then did bubble sort on that array.how to do bubble sort on a linked list as well as how to print a linked list.
Code:
#include<stdio.h>#include<stdlib.h> typedef struct node { int info; struct node *link;
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 ?
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.
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?
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;
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.
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 ....
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:
I'm new with working with random binary files. I have a class with a char* pointer stored inside of it, I also have a constructor that takes in a string (of any size) from the user. I then simply store this string into the char *. Once the string is stored in the char *. I reinterpret the instance, and I store the information into the random binary file. Everything works.
Question: Random files must know the size of the object that is being stored inside of it, so why when I enter strings of different sizes into the file, it appears to still be working. for example this is an example of the code:
class info { private: char *phrase; public: info(string n ="unknown"){ phrase = new char[n.size()+1];
[Code] ....
My point is, lets just say for example the object ETC, was some long string, this would still work for me. My question is, I don't believe each object is the same size because I allocate memory for the char pointer in the constructor.
Should I not do this just to be safe, and just use a char array instead of a pointer? (Even tho I would have set a pre-defined size for the string) or is something happening in the back to prevent this from not working?
... 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 :
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) ?
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: