C++ :: Error In Reading Struct From Binary File
May 20, 2013
Below is the code for reading a struct that was stored in a binary file. Problem is while reading from file I get the name without first character and age is always equal to zero which it should not be.
#include <iostream>
#include <conio.h>
#include <fstream>
struct abc {
char name[100];
int age;
[Code] .....
View 3 Replies
ADVERTISEMENT
Sep 28, 2013
I have a file in which I have written a structure called "Record".
Here is the struct definition:
#define IDSIZE 10
struct Record{
char id[IDSIZE];
int score;
};
[Code]....
View 1 Replies
View Related
Oct 12, 2014
I have this file want to read it source code [URL] ....
View 10 Replies
View Related
Apr 19, 2015
Your goal is to open this struct of students (the binary file). Once open, the first job is to print out each student. Afterwards, display all students with a gpa of 3.5 and higher. Finally, display all students with the major of Computer Science or Game Programming. Be sure to title each category of items.
He gave us a .cpp file and a .h file that we're suppose to use to run the program. He doesn't want us to change his original code, except we can add the needed code to run his code (i.e. Struct & Main).
My problem is that I get an Abort() crash message in VS2013 when I try to run it. Now, in line 95 of the cpp file if I replace the char* with "", it runs fine showing the GPA with blank entries for the other print parameters. I've read the Binary Files chapter of the Pearson textbook several times and it doesn't have anything to say about working with char pointers.
Header file:
#pragma once //Professor's code
struct StudInfo //Start of my code {
char* fName;
char* lName;
char* major;
double gpa;
[Code] ....
View 7 Replies
View Related
Mar 6, 2015
im trying to write an array of struct to a binary the array of struct is filled with data from a text file .
the program gives no errors or warnings but does not write anything at all to the binary file here is the main
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct matches
{
char teamA[20] ;
char teamB[20];
int scoreA ;
int scoreB;
[Code]....
View 6 Replies
View Related
Jan 11, 2015
I have a structure :
struct Entrainement{
string muscleCible, nom, unitesObjectif;
double objectifActuel, dernierObjectif, objectifInitial, capaciteInitiale, progression[10];
};
and I want to write in a binary file the structure. The following works perfectly....
(*pointeurFichierEntrainementBin).write((char*)&exercice, sizeof(Entrainement));
except when the string exceed 11 characters. I guess it's because it has to pick a fixed sized for the string? but what if I want to always be able to have string up to 200 character? because now I can't exceed 11..I know writing a string with c_str() works, but I would like to write/read the structure in one shot.
View 1 Replies
View Related
Sep 28, 2013
I have a file in which I have written a structure called "Record".
Here is the struct definition:
Code:
#define IDSIZE 10
struct Record{
char id[IDSIZE];
int score;
};
Here's the code where I wrote to the file:
Code:
Record record;
char* id = "H12345678";
int score = 50;
record.id = id;
record.score = score;
file.write((const char*)&record, sizeof(record));
}
Here's a screenshot of the file in windows: [URL].... To the left is the id, 9 characters. To the right, well I'm assuming that's the score that I wrote.
And here's the problem, reading from the binary file:
Code:
Record record;
fstream file(argv[1], ios::in | ios::binary);
if(!file){
cerr << "Could not open the file." << endl;
return 1;
}
char* id = new char[IDSIZE];
[Code]...
The ID reads perfectly. The score...always returns 0, despite that it should show "50".
View 4 Replies
View Related
Nov 20, 2014
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
struct inventory
[Code]...
This is my program output Enter the file name : "filename".txt ..... (Nothing shows up)
View 3 Replies
View Related
Nov 21, 2014
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
struct inventory {
int barcode;
char description[512];
[Code] ....
This is my text file
20123451
Sugar packet (1 kg)
2.50
560
21347652
Milo 3-in-1
12.50
200
20123453
Salt (1kg)
4.50
270
21347654
Nescafe 3-in-1
12.50
400
20123455
Tamatoes
4.00
100
21347656
Cucumbers
4.00
280
This is my program output
Enter the file name : "filename".txt
..... (Nothing shows up)
View 1 Replies
View Related
Mar 19, 2012
Basically I want to read data from text-file into two variables in a struct.
The text file is formated in the following way:
var1 [TAB] var2
The problem occurs when var2 is longer than one word and it doesn't really read the data into the struct. Here's the textfile.
DVD Kidmovie 1
Blu-Ray Spam Kings 2000
VHS The Short Road
Here's my program.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
struct movieData{
[Code] ....
View 1 Replies
View Related
May 3, 2013
I am reading from a file and saving in a struct table but they just saved as NULL
I erased the files stuff because they were working and taking a lot of space
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define WL 30
#define L1 150
#define L2 5000
#define L3 40
[Code] .....
View 3 Replies
View Related
May 4, 2013
I'm trying to read in lines for a file and storing it in an array. This is what I have so far. Am I allocating the memory correctly?
Code:
typedef struct {
/* declartion of variables */
} App
typedef struct {
[Code].....
How do I access the array content? I'm suppose to strtok the contents from the lines stored in the array and use it again.
View 2 Replies
View Related
Jan 31, 2014
I am trying to use struct to store variables from a text file and use them in the main program. I have first tried running the program without using struct and declaring the variables within the main program and it runs fine. But after using struct, it gives no compilation error and a segmentation fault as output. Also, if the size of file/variable size is unknown can I declare variables as char string[]??
The code is as below:
Code:
#include<stdio.h>
struct test {
char string1[10000];
[Code].....
View 4 Replies
View Related
Jan 4, 2014
I am parsing a binary data file by casting a buffer to a struct. It seems to work really well apart from this one double which is always being accessed two bytes off, despite being in the correct place.
Code:
typedef struct InvoiceRow {
uint INVOICE_NUMBER;
...
double GROSS;
...
char VAT_NUMBER[31];
} InvoiceRow;
If I attempt to print GROSS using printf("%f", row->GROSS) I get 0.0000. However, if I change the type of GROSS to char[8] and then use the following code, I am presented with the correct number...
Code:
typedef struct example {
double d;
}
example;
example *blah = (example*)row->GROSS;
printf("%f", blah->d);
View 7 Replies
View Related
Oct 20, 2013
i've defined an strcuct in .h file and i read its variable in a method in .cpp file ,but i'v got error.
.H file:
class myclass{
public:
struct opt_struct
[Code]....
when i declare the struct without static , it doesn't recognize my struct and with static i face linker error:
Error33error LNK1120: 1 unresolved externals
View 3 Replies
View Related
Mar 6, 2015
This is supposed to read a series of 16 bit binary numbers as short ints in the array memory. However, it only appears to be reading the first number.
Code:
short int memory[256];
void readFile(){
//read input file into int memory[]
FILE *ifp;
ifp = fopen("proj1a.dat", "r"); //input file
[Code] ....
View 9 Replies
View Related
May 30, 2013
How to store values from a .txt file delimited with semicolons (;) into a class which is then stored into a Binary Search Tree. After browsing Google for a few hours, and trying various examples of people using Vectors, I just can't seem to get my program to work using Object Oriented Programming with an instance of the class Person.
My two classes are Person, and BinarySearchTree as follows:
class Person{
private:
string first_surname;
string second_surname;
string name;
int ID;
[Code] ....
Ok so my text file saves the data of each person in the same order as the class with each value separated by a semicolon.
i.e. First_Surname;Second_Surname;Name;ID;Telephone;Score;
void fillTree( BinarySearchTree *b) {
string input[7];
Person p;
fstream file("scores.txt", ios::in); // reads text file
if(file.is_open()) {
[Code] ....
I understand that I get an error because a vector is saved as integers, and I am using strings, my question is, any other way to read the .txt file and save each data separated by a semicolon, into the Person class?
View 2 Replies
View Related
Jan 26, 2014
My program writes a vector to a file in binary. I want to erase the vector, then read the file to repopulate the vector then display.
Basically I want to erase the RAM memory and be able to use the file as memory. This is my current code but it is not reading the file correctly. I have checked the file to see that the writing part is working.
void read_from_file(vector<Info> &vector)
{fstream file;
file.open("info.dat", ios::binary | ios::in);
if (file.fail())
{
cout<<" FILE DOES NOT EXIST ";
system("pause");
[Code]...
View 7 Replies
View Related
Feb 9, 2014
I wanted to know if it is possible to read binary numbers(0's and 1's) from a file(text,picture, anything), and see them in the compiler.
View 14 Replies
View Related
Mar 6, 2013
I am having problems either writing data to a binary file or reading from the file. Through the process of elimination I am posting the code where the data is written to file to see if I can eliminate that as an option. I know the data is being processed correctly because, through the use of another function, I can view the data.
I also know that fwrite must be including some padding because the file size ends up being 576 bytes after it is written instead of 540 bytes (the size it would be if no padding is used). Here is my struct:
Code:
typedef struct {
char teams[25];
float wins;
float losses;
float pct;
int runsScored;
int runsAgainst;
} STATISTICS;
Here is where I initialize it:
Code:
STATISTICS stats[12] = {
{"Anaheim Arrays", 0.0, 0.0, .000, 0, 0},
{"Pittsburg Pointers", 0.0, 0.0, .000, 0, 0},
{"Indianapolis Integers", 0.0, 0.0, .000, 0, 0},
[Code] ....
And here is the function that writes my data. The sA array is only used to change the scheduled games based on the variable week.
Code:
void schedule(STATISTICS stats[]) {
FILE *f;
int sA[12], week = 0, runsPerGameA = 0, runsPerGameB = 0, runsAgainstA = 0, runsAgainstB = 0;
int index, a = 0, b = 1, i = 0;
[Code] .....
View 13 Replies
View Related
Mar 2, 2013
I'm reading a binary file and I want to read all of the letters, but I have noticed that it doesn't read all of the letters and I think it is because of appears as data.
View 11 Replies
View Related
May 30, 2013
Both arrays arr and pointers are the same size. I am having problems reading pointers from file into a new int array.
FILE* ky_pt=fopen("stashedclient","ab");
write(fileno(ky_pt), pointers, sizeof(pointers) );
pointerindex=lseek(fileno(ky_pt), 0, SEEK_CUR );
printf("pointerindex after writing array %d
[Code] .......
View 2 Replies
View Related
Feb 6, 2013
I am working in Eclipse, and it keeps giving me this error that I do not understand. In the fillTable function, "is >> kP[i]" Eclipse says: no match for 'operator>>' in 'is >> *(((TranslationTable<int, std::string>*)this)->TranslationTable<int, std::string>::kP + (+(((unsigned int)i) * 8u)))'.
#ifndef TRANSLATIONTABLE_H_
#define TRANSLATIONTABLE_H_
#include "KeyValuePair.h"
#include <iostream>
#include <cstdlib>
[Code]....
View 3 Replies
View Related
Mar 17, 2014
I am getting a weird error "The specified file is an unrecognized or unsupported binary format"
I have this >
#include <iostream>
#include "calculator.h"
using namespace std;
int calculator::getDisplay() {
return display;
} void calculator::enter(int nu
[code]......
View 6 Replies
View Related
Dec 3, 2013
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int encrypt_data(FILE *);
[Code] ....
I am trying encrypt the file "encrypt" when I enter it I get "Error in reading file"
I think its a problem with the fgets() and scanf()...I tried both fgets out and then scanf but I get the same error.
I look in the directory and see that when I enter a file to be encrypted a blank file with a "?" at the end is created in the directory. so I try to encrypt "encrypt" it shows error then creates "encrypt?"
I then tested it by entering a random file name that does not exist
EXAMPLE
Please enter file to be encrypted: fakefilename
Error in reading file.
I look in the directory the non existent file now is listed "fakefilename"
View 1 Replies
View Related
Mar 21, 2013
I am using OpenCASCADE environment to read STL file! I face a problem, with forward declaration error with the following
void StlReadIn::STL_Import() {
std::string FileName;
std::cout<<"
Enter the file name
";
std::cin>>FileName;
[Code] .....
Error message:
stlreadin.cpp:26:47: error: invalid use of incomplete type ‘struct StlMesh_Mesh’
/usr/local/oce-0.9.1/include/oce/Handle_StlMesh_Mesh.hxx:23:7: error: forward declaration of ‘struct StlMesh_Mesh’
View 2 Replies
View Related