C :: Comparing Structures From Binary File?
Jul 20, 2014
I'm wondering which method faster in comparing structures from a binary file.
Method 1:
Reading through the file one structure and a time and comparing each structure.
Method 2:
Reading numerous structures and allocating to memory , then reading through each allocated memory and comparing.
View 3 Replies
ADVERTISEMENT
Nov 5, 2014
I'm writing a function that compares two fraction. if the fractions are equal it returns 0. If the fraction in the first parameter is less than the fraction in the second parameter it returns a negative number. Otherwise it returns a positive number. in doing so convert the fraction to a floating point number.
typedef struct fracion {
int numo;
int denom;
}fraction;
int compareFractions (fracion, fraction);
[Code] ....
View 2 Replies
View Related
Aug 18, 2014
I am working on a airport reservation program and i have run into a brick wall. i want to ask the user its name, gender, passport no, age, destination, and travel class and figure out the day and flight code of the flight which i have saved in a binary file. now every thing works fine except the code and the day.
The programs important section
the flight class Code:
class flights {
char code[9],location[21];
public:
void display();
char *retloc() //to get the Location
[Code] .....
View 13 Replies
View Related
Dec 6, 2013
Following is the program I wrote it basically takes 9 inputs and then save them into binary file. then print out the data stored in binary data and find inverse of it then print the inverse out. but its stuck in a loop somewhere.
Code:
#include <stdio.h>
int main() {
int a[3][3],i,j;
float determinant=0;
int x;
FILE *fp = fopen ("file.bin", "wb");
[Code] .....
View 6 Replies
View Related
May 23, 2013
I want the user to enter the word and I want to check if it exists in a text file or not. I tried
int flag=0;
char word[50], input[50];
cout<<"Enter word to search for";
gets(input);
[Code] ....
But it does not seem to be working. Should I make changes to it or is there another way?
View 6 Replies
View Related
Nov 29, 2013
I was wonder if I can make 2 different size structures in a file. I wrote a code but It's apart of my school project and I havent compiled it yet, so Im just wondering will this work?
Code:
if((stsPtr = fopen("status.dat", "rb")) == NULL){
prinft("File could not be created/opened.
");
Error();
[Code] .....
View 1 Replies
View Related
Jun 9, 2013
I have to write a program that reads from a text file, which contains a list of stock hourly prices and the company names. Something like this:
78.52 82.56 75.10 71.97 Water Company
22.40 25.68 21.37 22.96 Mega Shipping Inc
There's suppose to one array of companies, where each company will be kept in a structure that contains: a pointer for the name, an array of the prices, and the average price for the day. The structures will be kept in an array of structures.
My question is, how do I read the data from the file and put the data from each line into the next structure in the array of structures? I read the numbers in fine. I just use:
Code: fscanf(fp, "%f", &companyAry[i].hourlyPrices[j]);
But my program crashes when I try to read the name.
Code: fscanf(fp, "%[^]", &companyAry[i].companyName);
I'm thinking it has something to do with the fact the companyName is a pointer.
My structure looks like this:
Code:
typedef struct {
char *companyName;
float hourlyPrices[NUM_PRICES];
float avgPrice;
}
COMPANY;
View 8 Replies
View Related
Apr 9, 2013
I tried normal swapping method like this (counter is number of structures written in file) :
Code:
fopen("books.txt","r+");
system ("cls");
for(i=1;i<counter-1;i++){
for(j=1+1;j<counter;j++){
fscanf(f," %[^,], %[^,], %[^,],
[Code] ....
But it doesn't do anything.
View 2 Replies
View Related
Nov 2, 2014
I'm reading the following file:
Osgood,Marcus 298542123 CHM FR mosgood@whatever.edu
Cronk,Melissa 873489021 BIO SR mcronk@whatever.edu
Pry,Seth 349908431 MTH SO spry@whatever.edu
Langlais,Susan 783323545 ME SR slanglais@whatever.edu
Davis,Nicole 987543345 PHY FR ndavis@whatever.edu
It's supposed to split it up into name, ID number, major, year, and email. The file reads it without any errors, and assigns name to the first part of the structure. However, ID gets assigned the ID, major, year, and email. Then Major gets assigned major, year, and email. Year gets assigned year and email, while email just gets assigned email. I don't know if it has something to do with the loop. For example, this is what I get what I print just the name and the ID.
Cronk,Melissa 873489021BIOSRmcronk@whatever.edu
Pry,Seth 349908431MTHSOspry@whatever.edu
Langlais,Susan 783323545ME
Davis,Nicole 987543345 PHYFRndavis@whatever.edu
Anyway. This is my function code for reading the array. I have it printing the ID number just to see if I can catch the errors earlier:
Code:
#include <stdio.h>
#include <string.h>
#include "functions.h"
void read_data(char filename[], studentinfo_t s[], int *size) {
FILE *infilep;
int countstudents = 0;
infilep = fopen("student_data", "r");
[Code].....
the name is reading correctly, but not anything else!
View 1 Replies
View Related
Feb 14, 2015
I am at a loss with an assignment. I am supposed to read from a text file, with an input of something like this: alphaproleone,stroke,42 1 and Store it into an array of structures and then output it with each word/number starting on a new line. My current code prints out only the first part, and the "a" in alphaproleone is the actual number "21".
#include <iostream>
#include <string>
#include<fstream>
#include<iomanip>
using namespace std;
typedef struct drugtype {
string name, target;
int effectiveness, toxicity;
[Code]...
View 1 Replies
View Related
Mar 6, 2015
im trying to read employee information from a file using structures but im having problems with getting the file to open and read in the information
Code:
Write a programt that inputs (at most 50) records from a sequential file
#include <stdio.h>
#include <stdlib.h>
struct employee // employee structure definition
}
[code]....
View 13 Replies
View Related
Nov 26, 2014
// my size is not decreasing when I erase a record.
//dvr_hwch.cpp
#include <iostream>
#include <iomanip>
#include <cassert>
using namespace std;
#include "hash_chn.h"
void print_menu( );
[Code] .....
View 1 Replies
View Related
May 13, 2012
I am trying to read from a data file that has input as :
12.0, 11, 123
14.0, 12.1, 3
And I want the program to read the data from the file and then make it into an array of structures and then print that array afterwards.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_INPUT 1000
int n =0;
int i = 0;
typedef struct {
double x[MAX_INPUT];
[Code] .....
The program when run gives the following output:
Ishtiaque-Mohammed-Khans-MacBook-Pro:Comp20005 IshtiaqueMKhan$ gcc -Wall -ansi -o ProjectB ProjectB.c
ProjectB.c: In function "main":
ProjectB.c:59: error: incompatible type for argument 1 of "print_array"
View 1 Replies
View Related
Dec 4, 2013
I have a program that stores health information the user inputs, one person at a time. The program works perfectly with the exception of storing the data...I need to open a file and read what health data it has in it already, if any, but store the new changes, and appended data to the array of structures, to the data in memory. All of the information is only saved back in the file once the program terminates. I'm not sure how to go about doing this, so I am also not sure what to put in the function for "Save and Exit" that the user can choose in order to exit the program.
Code:
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
struct strdatabase
{
char first[20];
char last[20];
char gender[2];
[Code]...
I tried playing around with this bit of code, but I'm not sure if I'm even on the right track.
Code:
FILE *fp;
fp = fopen ("students.txt","rb"); fseek(fp, 0, SEEK_END);
long pos = ftell(fp);
fseek(fp, 0, SEEK_SET);
char *bytes = malloc(pos);
fread(bytes, pos, 1, fp);
fclose(fp);
View 9 Replies
View Related
Feb 5, 2014
I need to create a program which could create text files of the bits stored in avi file/binary file. My first requirement is to show 0s and 1s in the text representation . My second requirement is to create an avi file from this text file. I have tried few codings but either they give me error or they not playing the reconverted binary files.
View 6 Replies
View Related
Apr 22, 2013
I am trying to get the code to read from the txt file one bite at a time and then write this bite into the binary file but i cant seem to get it working.
FILE *fpcust, *fpcustbin; //<<<<<-----point to both sales and customers text files, and the new .bin files for both
char buffer;
int ch;
int ch1;
fpcust = fopen("c:customers.txt", "r"); //<<<<-----pointing to the file
fpcustbin = fopen("c:customers.bin", "wb"); //<<<<<-----pointing to the new binary file, opening in writing binary
[Code]...
View 3 Replies
View Related
Apr 15, 2014
I just wrote a program for Huffman Encoding, where I take a text file, encode it in the form of 0's and 1's, and save that as another text file. However, this does not solve my purpose as it is taking even more space.
So I want to know how do I convert a text file containing these 0'S & 1's to a binary format.
Here is my program:
#include <stdio.h>
#include <string.h>
#include<fstream>
#include<string>
#include<iostream>
using namespace std;
typedef struct node_t {
struct node_t *left, *right;
int freq;
char c;
[Code]...
View 1 Replies
View Related
Sep 14, 2013
I want to convert a text file into binary file. I should create the text file by myself. I also use a structure for the components:
struct Data
{
int num;
char name[30];
};
I write information in the text file like this:
Data d;
cin >> d.num >> d.name;
fstream file("Name.txt");
file << d.num << d.name << '
';
If I have entered:
3 Steve
is easy to get this data. I just make another variables and get the data in them:
int num2;
char name2[30];
file >> num2 >> name2;
And everything is done. But what if I have this:
cin >> d.num;
cin.getline(d.name, 100);
file << d.num << d.name;
and the input is:
5 Steve Brown
I can get the number easy like before but how can I get the whole name? If I use:
int num2;
file >> num2;
char a[30];
file >> a;
I get only the first name "Steve". Can I get somehow and the second name in the same variable?
View 12 Replies
View Related
Nov 24, 2014
When reading a binary .img why is it when you read it by slurping in the file, then save it to a string and cout, you don't see the binary but random garbage?
View 11 Replies
View Related
Apr 3, 2013
I am using c to read and write contents of a file into other:
FILE *ptr;
status_t status;
uint32_t block_size, result;
uint32_t num_blocks;
char temp_buffer[1024];
}
[code]....
Is there way to see the binary content of this file.
View 2 Replies
View Related
Sep 5, 2014
What is the difference between reading from binary file between the following way:
struct aStrct{
int number;
}vars[];
while(file.good())
file.read((char*)&vars, sizeof(aStrct))
And
while(file.good())
file.read((char*)&vars[i], sizeof(aStrct))
i++;
View 2 Replies
View Related
Jun 12, 2013
Code:
#include<stdio.h>
void main() {
int x=0;
int y=0;
char c;
FILE* HUG;
FILE*fopen();
[Code] ....
View 10 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
Apr 17, 2013
I'm not the best at C but I'm trying to write a C function that basically opens a text file with assembler language does a syntax error check on it and then converts the binary data into hex.
This is my code so far:
Code:
#include <stdio.h>
#include <string.h>
int main(void)
{
FILE*fname;
char prompt;
char filename[15];
char text[100];
printf( "Please enter the name of the file you wish to open: " );
[Code]...
View 6 Replies
View Related
May 6, 2014
I use the following function to read doubles from a binary file:
Code:
int64_t read_current(FILE *input, double *current, uint64_t position, uint64_t length)
{
printf("asked for %" PRIu64" samples
",length);
printf("reading from %" PRIu64 " to %" PRIu64 "
",position,position+length);
union{
double d;
uint64_t i;
}
[code]...
As long as position+length doesn't exceed the end of the file, all is well. However, if it does, weird things start to happen. In particular, the apparent length of the file (that is, the value of "read" after the function has finished) becomes dependent on "length"). I know that "position" is never past the end of the file.
View 12 Replies
View Related
Dec 11, 2013
I'm attempting to split a large binary file into smaller manageable files for analysis. I've written most of the software but I'm stuck in a couple of places.
1. The binary file is split by looking at a couple of bytes to determine when to create a new file or continue appending to the current new file. The question is when I need to create a new file, how can I dynamically sign it a name? My intention is to rename each subfile by: "original_name" + new section id + ".log".
2. The start of each section is determined by a specific pattern (6 bytes of FF's). I'm running into an issue where the pattern check is checking for 5 bytes instead of 6 because the for..loop doesn't increment for one instance.
I've attached the code I have so far.
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <sstream>
using namespace std;
int append_to_file(FILE *f,long sec_start, long sec_end)
[Code] ...
View 2 Replies
View Related