benlogan1981
Programmer
OK, I'm having a few difficulties here. New to C++!
I have an input file of 0s and 1s, which are meant to represent bits. I want to read 10 of these characters in and create a 10 bit byte with them. Then I store this byte into an array to represent memory[256]. And then read another 10 'bits' from the file, etc
This is what I have, but when I try to progress from here I just mess it up...
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
char *infile = "data.txt";
int main()
{
ifstream iFile(infile, ios::in);
char memory[256];
char byte[10];
//read operation - for cycling through the bytes
//for(int i = 0; i < 16; i++) { //loop 16 bytes
//iFile >> memory; //from file, shouldnt be !!!
//}
//read operation - leave when input buffer is full
//read operation - bits for creating the bytes
for(int d = 0; d < 10; d++) {//loop 10 bits in bytes
iFile >> byte[d]; //from file
}
//read operation - leave when input buffer is full
for(int e = 0; e < 10; e++) {
cout << byte[e];
}//displaying a byte
//transfer contents of full input to the output
int x = 0;
for(int j = 16; j < 32; j++) {
memory[j] = memory[x];
memory[x] = 0;//clearing the input buffer
x++;
}
//write operation - to screen or file
for(int a = 0; a < 16; a++){
cout << "Input Buffer: " << memory[a];
cout << " Held at LOC: " << a << endl;
}
for(int b = 16; b < 32; b++){
cout << "Output Buffer: " << memory;
cout << " Held at LOC: " << b << endl;
}
//write operation
return 0;
}
I have an input file of 0s and 1s, which are meant to represent bits. I want to read 10 of these characters in and create a 10 bit byte with them. Then I store this byte into an array to represent memory[256]. And then read another 10 'bits' from the file, etc
This is what I have, but when I try to progress from here I just mess it up...
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
char *infile = "data.txt";
int main()
{
ifstream iFile(infile, ios::in);
char memory[256];
char byte[10];
//read operation - for cycling through the bytes
//for(int i = 0; i < 16; i++) { //loop 16 bytes
//iFile >> memory; //from file, shouldnt be !!!
//}
//read operation - leave when input buffer is full
//read operation - bits for creating the bytes
for(int d = 0; d < 10; d++) {//loop 10 bits in bytes
iFile >> byte[d]; //from file
}
//read operation - leave when input buffer is full
for(int e = 0; e < 10; e++) {
cout << byte[e];
}//displaying a byte
//transfer contents of full input to the output
int x = 0;
for(int j = 16; j < 32; j++) {
memory[j] = memory[x];
memory[x] = 0;//clearing the input buffer
x++;
}
//write operation - to screen or file
for(int a = 0; a < 16; a++){
cout << "Input Buffer: " << memory[a];
cout << " Held at LOC: " << a << endl;
}
for(int b = 16; b < 32; b++){
cout << "Output Buffer: " << memory;
cout << " Held at LOC: " << b << endl;
}
//write operation
return 0;
}