C++ :: Read From Txt File One Bit At A Time And Then Write Into Binary File

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


ADVERTISEMENT

C/C++ :: Best Way To Read One Bit At A Time From A Binary File?

Nov 9, 2013

I'm trying to do file compression/decompression in C and I need to handle one bit at a time.

I currently try to do:

unsigned char byte = fgetc(fptr);

and later

byte >>= 1;

but the problem is that I have to use the first bit of the byte and then treat the next 8 bits as one byte. The byte usage keeps shifting over in this way. It's probably quite clear that I'm a bit lost.

View 1 Replies View Related

C++ :: Read In Binary Files Then Write To Another File

Oct 11, 2014

I would like to read in binary files, then write them to another file.

I write a code, what works perfectly, if I would like to just copy the file to another. But I want to make it a little other.

If I open a file in hex-editor I also can see the ASCII values. But I would like get the ONLY the hex values to the other file.

For example:

d5 57 4f ad 30 33 0b 4e 49 a7 05 18 c4 90 66 d8 45 ac 39 3e 7d f1 a8 02 80
14 20 90 6e 20 12 38 0c 65 4a 28 d2 80 72 04 20 a9 4a 82 84 60 6a 0b 25
59 4c 30 c8 69 c0 ec fa 36 ed 3a da b1 9a 82 02 e0 bb 7e 41 87 02 f6 10 34
eb 95 93 63 01 6b 8d e1 d7 43 c3 df 92 5d 8a ed 57 61 4e 36 07 2a d7 56 2b
b5 0e 55 83 b4 76 8c b7 61 77 0e c9 76 0c 81 1b 01 63 0c 8b 73 57 d5 6d 4c
0c c2 0d 52 45 18

How could I make it?

View 4 Replies View Related

C :: Write / Read Tree Nodes Into A Binary File

Oct 20, 2013

I have a binary tree, and I want to store all information its leaves stores into a binary file and then read it.

What I tried:

A function that reads the tree, and whenever it finds a leaf, it writes in the binary file:

Code:
[...]
if(tree->right == NULL && tree->left == NULL){
fwrite(tree, sizeof(tree), 1, output);
}
[...] a

And in the main function:

Code:
[...]
for(i=0;i<5;i++){
fread(tree, sizeof(tree), 1, output);
printf("This is the leaf number %d", tree->num);
}
[...]

I'm trying to read 5 nodes just to see if its working but it isn't. The output shows the first node of the tree everytime.

View 2 Replies View Related

C++ :: Read And Write Binary Tree To File - Deserialization

Jun 24, 2013

So as a learning exercise, I am trying to read and write a binary tree to a file. After googling around, I decided to use a preorder traversal (including null nodes) to write the binary tree to the file. I got stuck trying to read a tree from a file. I can't figure out how to create an unknown number of nodes when they are needed. I could use an array, but that just seems bulky - plus it could run out of space. Is that what I have to do? I've heard of vectors before, but not very much.

View 5 Replies View Related

C++ :: Write And Read Class Objects In Binary File?

Jan 11, 2013

if i have 2 variables for which values are given by the user,then,does the information get stored into the file in the name of the variable,or just like packs of information.....if the former is true,how to extract the information of a particular variable alone from the whole file?

View 4 Replies View Related

C :: Binary File Write By User Input Then Printing Binary File Data Out

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

C :: Create File To Write Text And Read Back The File Content

Mar 15, 2013

The Objective Of This Program Is To Create A File To Write Text And Read Back The File Content. To Do That I Have Made Two Function writeFile() To Write And readFile() To Read.The readFile() function works just fine but writeFile() doesn't.

How writeFile() function Works? when writeFile() function Execute It Takes Characters User Type And When Hit Enter(ASC|| 10) It Ask "More?(Y/N)" That Means What User Want? Want To Go Next Line Or End Input?

If "Y" Than Inputs Are Taken From Next Line Else Input Ends.

But The Problem Is When Program Encounters ch==10 It Shows "More?(Y/N)" And Takes Input In cmd variable.If cmd=='Y' I Mean More From Next Line Than It Should Execute Scanf Again To Take ch I Mean User Input.But Its Not!!! Its Always Showing "More?(Y/N)" Again And Again Like A Loop.

Code:
#include <stdio.h>
void writeFile(void);
void readFile(void);
int main(){

[Code].....

View 5 Replies View Related

C++ :: Read From A Txt File And Then Write A New Text File With Sorted Line

Jun 11, 2014

I have a .txt file which I want to read from and then write a new text file, this time with sorted lines. It is easy to sort one value, but what about sorting entire lines based on one value?

I want to sort the lines based on the FIRST value.

Example text file contents:

values;data
5.01 100
2.9 342
2.69 43534
10.1 43
6.8 45324

Output: Text file containing

2.69 43534
2.9 342
5.01 100
6.8 45324
10.1 43

It's easy to do this if there was only 1 number on each line, but I do I sort all the lines based on the first number in each line?

View 2 Replies View Related

C/C++ :: Get Current Time And Write It To A File?

Jul 19, 2013

i have to write the current time to a file ?how to do it

View 2 Replies View Related

C++ :: Read One Value At A Time From A File

Sep 27, 2013

I'm trying to read in one value at a time from a file with this function, but its giving me back junk.

javascript:tx(
void ReadValue (istream &inF, int & num, bool & success) {
inF.clear();
inF.seekg(0L, ios::beg);
inF >> num;
cout << num;

[Code] .....

View 4 Replies View Related

C++ :: Write A Location In A Binary File

Jan 3, 2013

I have a std::vector of short ints that I need to write to a specific location in a binary file (without using .NET code). To that end, I wrote up this code:

Code:
ofstream fileStream (filePathString, ios::out | ios::binary);
int curPos = 2821;
fileStream.seekp(curPos);
int iter = 0;
while (iter < 1024*1024){
char bytesToWrite[2];
//Low byte
bytesToWrite[0] = LOBYTE(dataVector[iter]);

[Code]...

The code runs without crashing, but when I look at the file afterwards in a hex editor, every byte (even those outside the range I thought I was writing to) are replaced with 00. I suspect I'm missing something in my understanding of file streams. Did I write that code correctly? Seekp does move the pointer over the next byte to be overwritten, yes? Am I getting a memory leak somewhere?

View 5 Replies View Related

C++ :: Read One Number At A Time From Int File?

Sep 15, 2013

I have a file called example.txt . In that file, the int 123456 is stored. How can I read one independent number from that int? Lets say, I have an int variable called "Weight." How do I set weight equal to the number 1 from the int 123456 in the file?

View 4 Replies View Related

C :: Write Array Of Struct To A Binary File

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

C++ :: Write Struct With String In Binary File

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

C/C++ :: How To Write 0 Or 1 To Binary File In Bits Not In Bytes

Aug 20, 2014

How I write a 0s or 1s to binary file in bits not in bytes how can i do that ???

View 2 Replies View Related

C++ :: Write To A Binary File - Int Array Is Not Initialized

Oct 30, 2013

This is what I have so far

My function does not work and my compiler says my int array is not initialized

#include <iostream>
#include <cctype>
#include <string>
#include <fstream>
#include <stdio.h>
using namespace std;
void arrayToFile(ofstream tak, int *arr[], int size )

[Code] ...

View 9 Replies View Related

C :: Read / Write To File

Mar 3, 2013

How can I erase the data stored in /tmp/a.txt after every run of this code?

Code:

#include <stdio.h> // IO operations
#include <unistd.h> //for pid, ppid, fork functions
#include <sys/types.h> //for pid_t type, kill function
#include <stdlib.h> //for exit function
#include <signal.h> //for kill function
#include <sys/types.h>
#include <sys/stat.h>

[Code]...

View 3 Replies View Related

C :: Opening File - Read / Write

Aug 5, 2013

this is my read/write functions based the read from the last post! then went nuts with it! used the %19s%*s on the write to the file, solved all the probs on the read side! but any refining on this would be great. This is another program that i started with the forums, and started going my own direction!

Code:

void WriteAccount(int account,char *a[])
{
FILE *fptr;
char Memo[20];
char buff[20];
double Amount;
struct tm *sTm;
}

[code]....

the a[] is a string array with bank account names, and Account is the number on the menu based list.

View 7 Replies View Related

C++ :: Read / Write From File (fasta)

Dec 10, 2014

I'm looking to write a program in C/C++ to traverse a Fasta file formatted like:

>ID and header information
SEQUENCE1
>ID and header information
SEQUENCE2

and so on

in order to find all unique sequences (check if subset of any other sequence) and write unique sequences (and all headers) to an output file.

My approach was:

Prep: Copy all sequences to an array/list at the beginning (more efficient way to do this?)

Grab header, append it to output file, compare sequence for that header to everything in the list/array. If unique, write it under the header, if not, go on.

However, I'm a little unsure as to how to approach reading the lines in properly. I need to read the top line for the header, and then "return?" to the next line to read the sequence. Sometimes the sequence spans more then two lines, so would I use > (from the example above) as a delimiter? If I use C++, I imagine I'd use iostreams to do the reading.

View 1 Replies View Related

C/C++ :: How To Read And Write Certain Characters From A File

Oct 12, 2014

How to read some characters from file, I know we can move a pointer to some position using seekg() & seekp() function, get current position of the pointer through tellg() & tellp() functions. By moving the pointer to appropriate position using seekg(), we can read the whole line using getline() function. But is there any function which read certain characters from the current position of the pointer and write certain characters from current position of the pointer.

View 1 Replies View Related

C++ ::  How To Read And Write Certain Characters From A File

Oct 12, 2014

How to read some characters from file, I know we can move a pointer to some position using seekg() & seekp() function, get current position of the pointer through tellg() & tellp() functions. By moving the pointer to appropriate position using seekg(), we can read the whole line using getline() function. But is there any function which read certain characters from the current position of the pointer and write certain characters from current position of the pointer.

View 3 Replies View Related

C++ :: Read And Write The Values Of File?

Sep 22, 2012

the output of the password text file contains like this:

username
776655443322 (password encoded)

How to write the value in last line (3rd row) of the file. after that read and write or alter 3rd row value. I need logic using "C" language.

View 3 Replies View Related

C :: How To Read And Write A File Using Serial Port

Dec 29, 2013

Explain me a working code to read and write a file using serial communication.and i need to store that file.I know normal file handling in C, but how it is through serial port i am not getting.

View 1 Replies View Related

C :: File Write And Read As A Function Error

Sep 27, 2014

called object 'fptr_in' is not a function or function pointer
called object 'fptr_out' is not a function or function pointer

what can i do for the errors?(i mustn't use loop and arrays for the code)

Code:

#include <stdio.h>
void sum_of_2nd_and_3nd( FILE* fptr_in, FILE* fptr_out);
int main()
return 0;
}
void sum_of_2nd_and_3nd( FILE* fptr_in, FILE* fptr_out){
}

[code].....

View 2 Replies View Related

C++ :: Allow User To Open File And Either Read Or Write To It

Jan 30, 2014

So I've been turning my programs into classes and I run into errors.

So this program is supposed to allow the user to open the file and either read or write to it.

I've omitted the read part from it as I want to attempt that on my own .

I get these compile errors:

fileclass.cpp:13: error: ISO C++ forbids declaration of ‘choice’ with no type
fileclass.cpp:21: error: ISO C++ forbids declaration of ‘choice’ with no type
fileclass.cpp: In member function ‘int file::choice()’:

[Code] .....

View 10 Replies View Related







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