How to delete certain bytes from middle of a binary file?
Those bytes are in fact of a struct.
One approach I found was to re-write the whole data except the struct I want to delete. But may be its not good one if file size is in gb and I will have to write complete data again.
i just want to break the loop when user hit ENTER.But after that programm is stil working, i don't know why, becouse i have a code just like in book, i spend a lot of time with it.
int getinfo(student pa[], int n){ cout << "START" << endl; int i = 0; for(i; i < n; i++) { cout << "Studetn name"; char name[SLEN];
Basically after the 3rd run of the for loop, it encounters a contradiction. I want it to exit right there and then. Instead it continues to run the for loop. What can I do?
I'm get input from the user and then storing it in "s " and then trying make tokens, but it is not working, and after making tokens I'm counting them. Here is My Code
Code: #include <iostream> #include <sstream> #include <string> using namespace std; int main(){ string s;
[Code] ....
Here is my Output
Enter text: Entered Text is: This is String token 1: This token 2: is token 3: String token 4: Number of tokens: 3
The problem is that i want to store the first two strings "This" and "is" into two variables and how to remove token 4: which is unnecessary .
I know that you're allowed to use a char pointer to access any object but are you allowed to inspect a char array with a different type, say an unsigned integer without breaking the strict aliasing rule? My understanding is that it's not legal and could lead to trouble with trap representations but I just wanted to make sure.
I have function that returns historical data. I can access it, using file name. If I use file name, it reads that file and saves it to dictionary, so that in the future, if historical data is required for the same file, it does not read it again (it's lazy loading). If no file is supplied to the function, it tries to read file which is given in app settings.
However, for unit testing, I do not want to read any file. Instead, I want it to use small sample of hardcoded historical data. In order to do that, I think, I need to introduce interface to it. Then I can use some IoC to choose between different implementation for unit testing purpose and ordinary launch of application.
Function to get history is given as follows:
public static class Auxiliary { private static Dictionary<string, MyData> _myData; public static MyData GetData(string fileName = null) { // ... } }
I have created default Unit Test project with Visual Studio so, as far as I know, by default it uses MSTest as test runner and MSUnit as unit testing framework but it does not have any IoC container so I should manage NuGet packages for solution and install Unity.
As far as I know, MSUnit (aka Moles) can unit test static methods (it's unconstrained isolation framework, like Typemock Isolator, unlike NUnit) but still many people suggest not to use any static methods for unit testing.
Should I use shim or stub [URL] Stubs should be used for faking external dependencies and here it is not external library, but my own code.
I'm trying to make sure my code is written in smaller modules, so my first step is to create my initialization process in and external file to load the necessary data from external sources and set up things like the content of drop down list boxes.
My first attempt failed to give me access to the combobox items add function so I moved that code back into the form1.h file:
Code: public: Form1(void) { InitializeComponent(); // //TODO: Add the constructor code here // } void AddDate(char *date, int ID) { this->comboBox1->Items->Add("line 1"); }
It compiles fine, but the call to it in my Initialize.cpp file
Code: MarketView::Form1::AddDate("abs",1); Gives error C2352: 'MarketView::Form1::AddDate' : illegal call of non-static member function
OK, so I change "void AddDate" to "static void AddDate" and now get the error that "static member functions do not have 'this' pointers" so I go back to the "MarketView::Form1::comboBox1" situation where there is no legal syntax after "Box1 to get me to Items->Add
I've been an old fashion programmer for over 47 years. It seems as is the concept of programming computers has changed from the concepts of logic to memorization of complex syntax.
There has to be a simple answer to do this other than to write thousands of lines of code in one Form1.h file. I refuse to believe that the new programming concepts will not allow you to write code in smaller more manageable modules.
What is the proper syntax for breaking up the larger file into more manageable chucks?
Im using some motors which run off PWM pins.Theres a High byte and Loq byte register (PWMH,PWML).I have an int which i need to put into these registers but i dont know how???so for example
I need to read repeatedly data from a MPEG2 file to the buffer of 188 bytes and analyse data bit by bit.
I have the problem with correct bytes reading from file. In my code listed below I have two methods for that.
First one is lossing this bytes which in hex_base mode have 0 at the begining, eg: 03, 0F, etc.
The second method based on read function which need to have buffer as a char (lenght > 1 byte). Because of that I receive different values from that from file in some cases.
How can I properly read such file?
Code: #include <iostream> #include <fstream> #include <stdlib.h> #include <windows.h> using namespace std; int main() { fstream plik_in;
I am encoding some information in a binary file, and I want to check what I am doing by printing out all the bytes that represent the file.
This is being done by opening a pointer to the file with fopen, reading in each byte of data as a char, and then writing this char to the screen.
I have some image files (e.g. "image.jpg"), whose structure I know, so that I can test my program.
When I print out the chars, they are initially correct, and follow the structure of the file as expected.
However, after about 40 bytes, I find that every subsequent character is ' ' i.e. a blank character.
I then created a CharToBin function, which allows me to print out the actual bits in the char. When doing this, it shows that all the bits are 1 for the characters. i.e. most of the file is represented by 1's, which is clearly not correct.
This happens on all the image files I have tested, and furthermore, on several other non-image files. They all start printing out ' ' after a while. However, all these files are fine and not corrupted, e.g. the image files display correctly.
Code: #include <fstream> #include <iostream> #include <sstring> #include <string> #include <stdio.h> using namespace std; string CharToBin(char ch) { bool bits[8]; for (int i = 0; i < 8; i++)
I have a FILE stream, and I want to create a function that streams a specified number of bytes (up to four bytes) and returns the value of this, as an integar.
For example, supposing that my FILE has the following data, in hex: 74 C8 02 33 F2 7B....... I then want to stream three bytes and store this as an integar. So, I want to stream "04 08 02". The data stored in the integar should then be "00 74 C8 02", because I have not streamed anything into the first byte. By converting the hex to dec, the integar should then be of the value 7653378 (if it is unsigned).
To try to achieve this, I have written the following function. I create an integar and initialise it to zero, then take each byte from the stream, and OR it with my integar. Then, I shift the integar left by 8, and read the next byte, and so on.
The problem is, when I convert "c" to "c_int", it adds on a load of 1's to the left of the "c" data. This then means that the OR comparison changes all those bits in my integar to 1.
How to solve this? I am also wondering whether there is a much more simple way of doing this, rather than having to write my own function....
Code: int StreamFileToInt(FILE *fp, int num_bytes) { char c; int c_int; int x = 0x0000; for (int i = 0; i < num_bytes; i++) {
I made this program to convert bits to bytes, because I'm so sick of seeing ISP's advertise speeds in megabits, which I consider an intentional attempt to decieve :P And I think I've finally understood how the return value of scanf works since the last time I posted here, so my program can check to see if an integer was entered before processing the input, but I'm stuck on how to make the whole program start over if an integer is not entered. I have a hunch it would involve a loop, but I can't figure out how to make the program start over at "How many mb do you need converted?" if an integer is not entered into scanf..Here is the code I have so far:
Code:
#include <stdio.h> int main () { int b, mb, kb, Byte, kB, mB, gB; char term; }
[code]....
and my program makes the assumption for now at least, that mb will be inputted because that's the unit of measurement that i usually see advertised, and i didn't bother making an if statement to print a conversion in terms of gigabytes because i've never heard of a connection that fast :P
how to combine two bytes (each byte is 8 bits wide) in order to get the original value. I am displaying values(from 0 to 500)sent from my microcontroller on the GUI.I can successfully display values from 0 to 255 as this requires just sending a byte. However sending values from 256 to 500 requires sending two bytes. The problem I am having is that I was unable to re-combine the received two bytes in order to get the original value. Below are my lines of code:
int main( void ) // this is the main function inside the microcontroller { sei(); USI_TWI_Master_Initialise(); Spi_Master_Init(); while(1) // I am using this loop to send 500(111110100) { Transmitt_Receive(244);//this function sends LOW BYTE of 500(11110100) _delay_ms(1000);
[code]....
When I combined the two bytes using the above arrangements, instead of getting 500 my GUI displayed 62708.I got the same result when I used BitConverter.
I want to read a single byte from a wifstream. With an ifstream I would use read(), but given that the char type for an wifstream is wchar_t (2 bytes), this is also being used by read(), so how can I read a single byte from such a stream?