C++ :: Unwanted Char / Byte When Joining Files

Dec 12, 2014

I wrote the a piece of code to join three files but there is an unwanted char/byte "y" that shouldn't exist but does.

The result is something like
Code: *FILE1**FILE2*y*FILE3*y

Instead of

*FILE1**FILE2**FILE3*

My two questions are: Why is it there, and how can I stop it from appearing.

Code:
ifstream in("Text1.txt", ios::in | ios::binary);
ofstream out("Text3.txt", ios::out | ios::app | ios::binary);
if(in.is_open() && out.is_open()) {
while(!in.eof()) {
out.put(in.get());

[Code] .....

View 6 Replies


ADVERTISEMENT

C# :: Store Each Char Of A String Into Byte-array?

Apr 25, 2014

I am trying to store each char of a string(string a ="1100") into a byteArray ( byte[] byteArray = new byte[4]. its not showing any error but its storing like below:

byteArray[0] = 49
byteArray[1] = 49
byteArray[2] = 48
byteArray[3] = 48

and what i want is

byteArray[0] = 1
byteArray[1] = 1
byteArray[2] = 0
byteArray[3] = 0

I don't know why but its replacing 1 with 49 and 0 with 48.what am I doing wrong or how to do this?

my code is as below

byte[] byteArray = new byte[4];)/>
int binArrayAdd = 0;
string a ="1100";
foreach (char Character in a)
{
byteArray [binArrayAdd] = Convert.ToByte(Character);
binArrayAdd++;
}

View 4 Replies View Related

C Sharp :: Byte Array To Char Conversion

Jul 26, 2012

- API Function

TestSend(ref char data, ref int len, char slot);
---------------------------------------------------
 Byte[] IccSelect = new Byte[7]{
                              0x00,    
                              0xA4,    // INS 
                              0x04,    //1                              0x00,    //2                              0x0E,    
                              0x31,    
                              0x50,    
                              };  
Int32 len = 20;

TestSend(ref ??, ref len, '0');//byte array to char conversion

View 1 Replies View Related

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

Dec 26, 2013

I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...

i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....

------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";

[Code] ....

When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.

The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.

I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.

When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..

input = input / BASE; I get C9 where I expected to get 48.

My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?

View 6 Replies View Related

C++ :: Program Producing Unwanted Integers?

Jan 17, 2012

I have done some programming or rather have written and implemented some algorithms in code (is there a difference? :-)) but am having some teething problems with a project I am currently working on.

To start with I am simply reading in the data from a .txt file into a vector. This is the code that I currently have:

Code:
#include <iostream>
#include <fstream>
#include <cerrno>
#include <vector>

[Code]....

This compiles fine but currently outputs a different integer everytime I run the program. I can remember having this problem when I started coding before using a different language and if I remember correctly it was quite easy to resolve. I thought it was because I had missed off the 'return 0' but it is something similar I think.

View 3 Replies View Related

C++ :: Creating And Joining String Objects - Suffix Increment Operator In Cout Statement

Mar 7, 2013

Here is the code:

// Creating and joining string objects
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::getline;
// List names and ages
void listnames(string names[], string ages[], size_t count) {

[Code] ....

I may be wrong, but the problem seems to be in the function "listnames". Specifically, the output statement inside the while loop. I don't understand , how the ++ operator is behaving in this statement. The output produced does not match what's printed in the book. I usually just type all the examples, but with this one I also downloaded the source code from the book's website to make sure the error wasn't due to mistyping.

View 4 Replies View Related

C/C++ :: Error In Vector Pushback - Creating Random Unwanted Numbers

Apr 12, 2014

I'm currently writing a chunk of code that will take inputs from the user and push them into a vector until 0 is entered, at which point it will break the loop and continue on with the rest of the program. This is nothing I haven't done before, but I have never encountered this error.

The code chunk looks like this:

typedef vector <int> ivec;
int main() {
ivec nums;
int input;
while (true) {
cout << "Enter a positive integer, or 0 to quit" << endl;

[Code] ....

My standard testing input has been 3 5 6 3 8 (then 0 to quit), so one would expect my sequence to be 3 5 6 3 8...but instead after the 8 I get a random number value that is usually quite large and I cannot figure out where it comes from (ex. 3 5 6 3 8 201338847).

View 9 Replies View Related

C++ :: Char Pointers And Random Binary Files

May 6, 2013

I'm new with working with random binary files. I have a class with a char* pointer stored inside of it, I also have a constructor that takes in a string (of any size) from the user. I then simply store this string into the char *. Once the string is stored in the char *. I reinterpret the instance, and I store the information into the random binary file. Everything works.

Question: Random files must know the size of the object that is being stored inside of it, so why when I enter strings of different sizes into the file, it appears to still be working. for example this is an example of the code:

class info {
private:
char *phrase;
public:
info(string n ="unknown"){
phrase = new char[n.size()+1];

[Code] ....

My point is, lets just say for example the object ETC, was some long string, this would still work for me. My question is, I don't believe each object is the same size because I allocate memory for the char pointer in the constructor.

Should I not do this just to be safe, and just use a char array instead of a pointer? (Even tho I would have set a pre-defined size for the string) or is something happening in the back to prevent this from not working?

View 5 Replies View Related

C++ :: How To Read A Bit From A Byte

Mar 30, 2013

What is the most efficient way to read a bit at a particular position in a byte?

View 13 Replies View Related

C++ :: String To Int To Byte?

Aug 16, 2014

Right now im creating a program that use xbox inputs and then send out keyboard functions using sendInput();

It works fine, but now im creating a system wich lets the user of the program change the settings in a textfile. Wich will then change what the controllers bindings are.

example, if settings.txt says: Y=button(0xIE)

i want the program to know that when xbox button Y is pressed, execute a sendInput function to the Key: A (0xIE).

The problem is that the virtual keycode (0xIE) i take from the settings.txt is stored as a string (lets say it is stored in string Y_event)and input.ki.wScan has to be of type BYTE. i made a function wich changes string into int. (because input.ki.wScan seems to be fine getting a int?)

int stringToInt(string insert) {
char back[20];
for(unsigned int e=0;e < insert.length();e++) {
back[e]=insert[e];
} return atoi(back);
}

but when i run the code nothing happend...

In the code i have a function wich executes the keypress: void pressbutton(int key, int time)

when i send in the converted string it doesn't work but when i send in: (0xIE) it works.

pressButton(stringToInt(Y_Event),50) // doesn't work
pressButton(0xIE,50) // works

focus on the last part that i wrote.

View 3 Replies View Related

C++ :: Most Efficient Way To Read A Bit From A Byte?

Mar 30, 2013

What is the most efficient way to read a bit at a particular position in a byte?

View 3 Replies View Related

C/C++ :: Returning Byte Value From Memory?

Mar 16, 2014

I'm trying to get the current time for a game and print that to the games chat window. I'm already injected into the process do I don't think I need ReadProcessMemory.

The value i'm trying to read is the game hours 1-12.

//doesn't work
byte time_hour_get ( void )
{
return *( byte *)0x00B70153; //the address to the memory containing the
}

addMessageToChatWindow((char*)time_hour_get); -> when I call this function it looks like s , . I want it to return the integer value like cheat engine. I used byte when scanning for this address

View 1 Replies View Related

C :: Program To Hide Files Behind Other Files Using Alternate Data Streams

Apr 5, 2013

I am writing a program to hide files behind other files using Alternate Data Streams in Windows NTFS file systems.

The program is as follows:

Code:

#include <stdio.h>
#include <stdlib.h>
int main(void){
char hostfile[75], hiddenfile[75], hiddenFileName[15] ;
printf("Enter the name(with extension) and path of the file whose behind you want to hide another file: ");
scanf("%75s", hostfile);

[Code]...

The complier is showing error as "Extra Perimeter in call to system" but I am not getting where?

View 4 Replies View Related

C++ :: Display Last 1000 Lines From Multiple Text Files (log Files)

Jan 16, 2014

I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.

I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.

What is the best way to do this? Even an outline algorithm will work.

View 6 Replies View Related

C :: Byte Ordering In Binary Buffer

Apr 13, 2014

Basically it has to do with the byte ordering in a binary buffer vs the typing of a variable used to hold it.

To give you an example, if I have a buffer (say of indefinite length), and a ptr "ptr" pointing to a byte in the buffer (say, C0), such that if I open the buffer in a binary viewer it reads like this: Code: C0 DD FE 1F Such that this is true:

Code:
/*ptr is uint8_t*/
*ptr == 0xC0

Then I do this:

Code:
uint16_t var;
var = *(ptr+1);

I would expect the result to be:

Code: DD FE /*56830*/

Though if I print that out with:

Code:
printf("%u
", var);

It'll print:

Code: 65245 /*(FE DD)*/

Now obviously it's byte swapped, but what is causing that? I'm assuming if I just stream that out to a file byte by byte it'll be fine, so it's something with the 16 bit data type (also have seen this issue with a 32 bit data type, where all 4 are in reverse order). Is there any way to 'fix' it except bit shifts & masks?

View 14 Replies View Related

C :: Locations In The RAM Addressed Per Word Or Per Byte?

Sep 20, 2014

Are locations in the RAM addressed per word or per byte? I am using a 32 bit machine, so I think that it means that on my PC a word would be 4 bytes.

View 11 Replies View Related

C# :: Reading A File Into A Byte Array?

Jun 25, 2014

I basically want to create a save editor application that will enable people to alter various values in the save by clicking on releveant buttons and then also for the editor to auto update the checksum when changes are done.

The save file is in hex so from what I can gather I would need to create a button to open the file using 'open file dialogue' and then read the file into a byte array so that the values can be called at any time when a particular butto is pressed and the application will then seek to the point in the file to make the required changes.

View 3 Replies View Related

C# :: Get Posted File From Byte Array

Oct 7, 2014

I have an application that has its own embedded web server. I am trying to add jQuery/Ajax file upload capabilities to the application however, I am running into issues getting the posted file. The jQuery/Ajax portion is similar to this method here. Due to the way the webserver was written (its in a dll and I do not have access to the source), the posted file comes in as a byte[]. If I try to save the byte array directly to file using:

File.WriteAllBytes("path", ByteArray)

I end up with a corrupt file that I cannot open. I believe this is because the byte array also contains the posted file header info (Content-Disposition, name, filename, etc.). If I view the contents of the byte array using:

System.Text.Encoding.Default.GetString(ByteArray)
the header info can be viewed as:
------WebKitFormBoundaryQfPjgEVpjoWgA5JL
Content-Disposition: form-data; name="0"; filename="someimage.png"
Content-Type: image/png
‰PNG

Based on the selected file size and the size of the byte array, the entire file is in the byte array. How can I go about extracting and saving the posted file from the byte array?

View 2 Replies View Related

C# :: Reading Byte From Serial Ports

Jun 8, 2014

how to use this function:

ftStatus = myFtdiDevice.Read(readData, numBytesAvailable,ref numBytesRead);

to read byte from the serial port.This function is part of the DLL that came with the chip(FT2232D) I am using on my board.I want to use the function to read a byte from the serial port and then send the value to the Graphic user interface.Unfortunately I was unable to get the expected value on my GUI.If I send for instance 40,what I get on the GUI are letters instead of the number 40 or at times the GUI will not even respond.Below are my lines of code I used to read the byte from the serial port:

The following instructions are executed whenever the CHECKBOX is checked

private
void checkBox1_CheckedChanged(object sender, EventArgs e)
{
UInt32 numBytesRead = 0;

[Code].....

View 3 Replies View Related

C/C++ :: How To Write Byte In 8051 Correctly

Nov 16, 2012

i have a hex code and need to write it in 8051

if the hex code is
"11 22 33 44 55 66 77 88"
"88 77 66 55 44 33 22 11" (hexadecimal)

but the result is

11 22 33 44 55 66 77 88 FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF

it is should be

11 22 33 44 55 66 77 88 88 77 66 55 44 33 22 11
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF

problem is ...
it can not write second hex code
just only write first hex code

i use serial port , VB6 ,keil C

View 4 Replies View Related

C++ :: Binary IO - Read 4 Byte Int From A File

Feb 26, 2012

Trying to write very simple code to read a 4 byte int from a file.

code:

int tester;
FILE *fp;
fp=fopen("/home/bdluser/skeleton.blx","rb");
fread(&tester,sizeof(int),1,fp);
printf("tested 1 byte read should be 1: %i",tester);

I have tried editing the binary file....it outputs similar large numbers

00000000000000000000000000000001 outputs 808464432
0x00000001 outputs 808482864
0x10000000 outputs 808548400
10000000000000000000000000000000 outputs 808464433
x01x00x00x00 outputs 813183068
x00x00x00x01 outputs 813183068 same....

etc.etc. It just keeps returning the same large integers. I thought they were memory addresses but its consistent output/input so I guess not.

View 2 Replies View Related

C++ :: Printf With Signed Short / Byte

Jul 17, 2012

I am using print/sprintf with a "%i" format string. Works fine if the input is indeed a 32bit integer. But how can i put in 8/16 bit (ie short & byte) 'integers'? If i just throw them in, they are always taken as unsigned, as the topmost bit/s is/are casted to zero... [URL] ....

View 3 Replies View Related

C++ :: Check If Given 8 Byte Is A Valid Double

May 28, 2014

Is there a function in C/C++ that can check if a given 8-byte data block is a valid double value in the valid range?

View 7 Replies View Related

C++ :: Byte Array To Double Conversion?

Dec 5, 2014

I'm trying to understand why a conversion from a byte array (unsigned char) to a double works when done one way and not antoher.

In the example code I test by hard coding an unsigned char array of the same bytes that the double consists of.

When I copy the bytes to a long long and cast to double the result is not the original double but if I use a struct the bytes can be set and the conversion happens.

Seems to me that both ways should work. I'd just like to know what is going on with the "struct way" that makes the conversion correct. I see in debugger that the bytes in memory are the same for piAsLong and u.bytes.

My compiler is VS 2012 and a long long and double are both 8 bytes (tested with sizeof). This is learning activity only.

Code:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
union {
double d;

[code]....

View 6 Replies View Related

C++ :: Convert 2-byte Array To Short Int?

Nov 18, 2012

I'm having trouble reading a block of bytes into a vector of short ints. My code is as follows:

Code:
FileStream.seekg(2821);
vector<short> g_Data;
int iter = 0;
g_Data.reserve(maxNumOfInts);

[Code] ....

The relevant block of data starts at offset 2821 in the file. Every two bytes are a signed short integer. What's odd is that it's giving me the correct results only part of the time. At offset 1052421 and 1052422 there are two bytes 40 and 1F that are correctly read in as 8000, but at offset 1052415 and 1052416 bytes 88 and 13 are read in as -120 instead of 5000.

I don't see anything wrong with my code, though, unless I'm misunderstanding completely how to convert an array of two bytes into a single float. Is my method correct? Better still, is there some way to just convert en mass an array of bytes into a vector of signed short ints?

View 5 Replies View Related

C++ :: Encoding Byte Array Data?

Apr 23, 2012

I'm trying to parse some binary data in the form of an array of bytes and I've come across something that is confusing me related to the representation of data as chars versus ints. It's a bit of a long story, but the byte array contains a mixture of character data and integer data which I' having trouble unravelling. The problem seems to arise from the issue below:

Code:
const char * ch_arr = "abcd";
const unsigned int * ui_arr = (const unsigned int*)ch_arr;
cout << ui_arr[0] << endl;
unsigned int ui = 'a';
ui = ui << 8;
ui |= 'b';
ui = ui << 8;
ui |= 'c';
ui = ui << 8;
ui |= 'd';
cout << ui << endl;

I expected both the output lines to be the same, since they contain the same bytes (I believe), but I get:

Code:
1684234849
1633837924

View 4 Replies View Related







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