C++ :: How To Properly Concatenate Two Items That Contain Binary Data

Mar 30, 2015

I have two std::string data items that contain binary data (so it may have the null character!). What is the proper way to concatenate them to preserve all of the data? I am guess a simple:

string string3 = string1 + string2;

Will not work, as it will terminate string3 on the first NULL character it encounters.

View 3 Replies


ADVERTISEMENT

C++ :: Binary Search Tree - How To Implement Insert Function Properly

Nov 18, 2013

I am unable to implement the insert function properly, every time i run the program i just get the first value and name, I am not getting other Id's and name.

"(Header File)"
#include <iostream>
#include <string>
using namespace std;
class node{
public:
int ID;
string name;
class node *left, *right, *parent;

[Code] .....

View 4 Replies View Related

C++ :: Read N Data Items Into Two Arrays (X And Y) Of Size 20

Apr 1, 2013

Trying to do a homework assignment for a class and how to read a file into an array. I've looked in our book and on several other forums and cant seem to find any examples of this. Below is the assignment I'm working on. I have a shell of the program that I can get to run, but getting a .txt file to read into an array is something I cant seem to figure out how to do.

Write a program to read N data items into two arrays, X and Y, of size 20. Store the product of the corresponding pairs of elements of X and Y in a third array Z, also of size 20. Print a three column table that displays the arrays X, Y, and Z. Then compute and print the square root of the sum of the items in array Z. Compute and print the average of the values in array Z and print all values above the average of array Z. Determine the smallest value in each array using only one function.

Use the two data files named DATAX.TXT and DATAY.TXT.

You must use functions for the reading of the data, computing the average, printing the three column table and printing the values above average.

View 3 Replies View Related

C++ :: Create Data And Saves It Into Block - fstream Appearing To Not Function Properly

Apr 14, 2013

I'm working on a program which creates data and saves it into blocks (different files), then reloads and converts it all. the .ftl file saves properly, but for some unknown reason, it won't let me open it for input after.

Here's the significant code:

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

stringstream filename;
stringstream newfilename;
string Filename;

[Code] ....

setblock will typically = 3, but for testing purposes is set to 1. this really has me confused. the compiler i'm using is Dev-C++ 5.2.0.1 on xp. i have tried pausing the program after the output file is closed, confirming the file has been created in the proper directory before continuing but still fails the .is_open() check.

View 4 Replies View Related

C/C++ :: Know That Data Written To Shared Memory Segment In Unix Is Stored Properly

Mar 8, 2012

I am trying to write a client/server application that takes input to an array of structures from the user,stores the data in a shared memory segment and then writes the same to a file when I close the application. How do I get started? And how do I ensure that the server stores the data correctly? Also, the server needs to be a concurrent server that accepts connections from multiple clients.

View 1 Replies View Related

C :: Store Data In Binary File Then Use It To Find Inverse Of Matrix Form Of Data

Dec 6, 2013

I need to find inverse of a matrix data in binary file should be used to form matrix.its not finding inverse correctly rest is working good.

Code:
#include <stdio.h>
void createbin();
void display();
void inverse();
int main()
{
createbin();
display();
inverse();

[Code] ....

View 4 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 :: 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++ :: How To Concatenate String Plus Int

Mar 17, 2014

I want to concatenate string+int so i make like that

Code:
for(int i=0;i<n;i++)
{
name="obstacle"+i;
cout<<name;
}

I get in the window
obstacle
obstacl
obstac
obsta
obst
...
..
o

but i want instruction that allow me to get

obstacle0
obstacle1
obstacle2
...

View 6 Replies View Related

C++ :: How To Concatenate Two Vector Char

Dec 1, 2013

This seamed as a simple thing but i am getting something i did not expect: Example:

Code:
vector<char> StrJoin(SubjSeq.size()+ QuerySeq.size());
cout << StrJoin.size()<<"
"; // size x

StrJoin.insert( StrJoin.begin(), QuerySeq.begin(), QuerySeq.end() );
StrJoin.insert( StrJoin.begin(), SubjSeq.begin(), SubjSeq.end() );

cout << StrJoin.size()<<"
"; // x*2

All structures are vector<char>. when i do the above my characters form Query and Subject are copied in my new vector called StrJoin but the size of that vector is twice the size then it should be.

View 3 Replies View Related

C :: Trying To Concatenate 2 Elements From Array

Oct 19, 2013

Trying to concatenate the 1st and 2nd element from an array of chars. Then this to be used as a hex value.

so for example
specs[0]='f'
specs[1]='4'

concatenate_value=0xf4

View 9 Replies View Related

C :: How To Concatenate Two Integers Into One Integer

Oct 15, 2014

How i can concatenate two integers into one integer. I have code that concatenate two integers but if the 2nd integer is zero it won't work. How can i modify it so that it can cater the case of y=0 too.

Code:

int concatenate(int x, int y) {
int pow = 10;
while(y >= pow)
pow *= 10;
return x * pow + y;
}

View 12 Replies View Related

C :: How Macro Works To Concatenate Three Integers

Nov 15, 2014

when i was finding a way to concatenate three integers in C, I came across a snippet like this

Code:

#include<stdio.h>
#define cat(a,b,c) a##b##c
int main()
{
int d;
d=cat(1,2,3);
return 0;
}

How the macro works here? I am unable to understand the function '#' plays in the macro.

View 1 Replies View Related

C :: Concatenate Array Elements More Than Specified Range

Apr 19, 2013

I m concatenating specific range of digits that are same from an array "element" . I have problem with range. As in my case the range is col_elem[ii]=4, but it will continue reading the next element if it is the same. My code is:

Code:

int element[8]={0,1,3,3,3,0,1,2};
col_elem[ii]=4;
for (rr=0; rr<col_elem[ii];rr++){
join_tmp[qq]=rr;
while ((element[ii]== element[ii+1]) ) {

[code]....

View 4 Replies View Related

C/C++ :: Function To Concatenate Two Linked Lists

Mar 6, 2014

The objective of the project is to become familiar with linked lists by writing a series of basic functions that allow us to manipulate a set of linked lists. I've completed all of the functions except for one.

The function I am stuck on is supposed to do the following:

concatenates list1 and list2 to form a new list,
and returns a pointer to this new list;

Note: new list contains copies of all nodes in list1 and list2 */

View 7 Replies View Related

C :: Concatenate Strings In Array (2D) - Function Not Working Right?

Sep 6, 2013

I have a function that concatenate the strings in an array(2D)

Ex 1: Sean Connery Micheal King James Wood

Result: SeanConnery MichealKing JamesWood ...

The concatenation function working correctly and displays correctly in the function. But if I make another function to display it, it shows this

Ex 2: SeanConnery Sean MichealKing Micheal JamesWood James..

It adds to first name. Why?

Code:
void Concatenation( char dest[200][13] ) {
// loop through and concatenation the strings
for(int i=0;i<200;i+=2) {
myStrCat(dest[i],dest[i+1]); // mystrcat is equalto strcat()

[Code] .....

View 4 Replies View Related

C :: How To Concatenate Array Index For Same Elements For Specified Range

Apr 22, 2013

Actually i found some mistakes in my post. So here is the modified version. I want to concatenate the indexes of elements of array that has the same value for specific range.In my case the range is 4

Code:

int element[8]={2,2,0,3,3,0,1,2};
col=4;
int rr;
int qq=0;
for (rr=0; rr<col;rr++){
join_tmp[qq]=rr;
while ((element[rr]== element[rr+1]) ) {
join_tmp[qq]= concatenate(rr+1, join_tmp[qq]);
printf("%d
",join_tmp[qq]);
rr++;
}
qq++;
}

Code:

//FUNCTION TO CONCATENATE INTEGER VALUES OF SAME GROUP IN A COLUMN
unsigned concatenate(unsigned x, unsigned y) {
unsigned pow = 10;
while(y >= pow)
pow *= 10;
return x * pow + y;
}

Code: I want input like
10
2
3
Instead i get
10
2
34

how can i fix it so it will only iterate to the specific range?

View 2 Replies View Related

C++ ::  Send Binary Data Over TCP/IP

Sep 3, 2014

I am writing a client-server program in C++ using C libraries. The server listens for a connection and when one is found, it is supposed to send a binary file(an image in my case) to the client. The server is sending the binary file perfectly after opening it and reading its contents into a buffer that is dynamically allocated in the SERVER file.

The problem begins when the client file is supposed to recv() the file, I do not know how I can allocate a buffer big enough for the file to be received. I know how to use malloc() and new, I prefer malloc() for executable size customization. Assuming the file being sent is 11000 bytes(note that this is an assumption and the client can not know the file size because the file size is dynamically generated by server).

How can the client generate a dynamically allocated buffer big enough to hold 11000 bytes?
OR
How can the client store the data in a buffer using recv() without knowing the file size.

Below is part of the code that does the send()'ing and recv()'ing.

SERVER

FILE *img = fopen("img.jpg", "rb");
fseek(img, 0, SEEK_END);
unsigned long filesize = ftell(img);
char *buffer = (char*)malloc(sizeof(char)*filesize);
rewind(img);
// store read data into buffer

[Code] ....

This outputs all the binary code perfectly but it is a bug because it can't be written to a file. Is there a way to dynamically increase the buffer until all filesize is received? Certainly, buffer needs to be dynamically allocated or program crashes ...

Also one more thing, when I telnet the server from command line, telnet displays all the output perfectly as well

Maybe telnet is storing data into a buffer behind the scenes, if so, how?

View 9 Replies View Related

C :: Converting Binary Data In A Txt File Into HEX

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

C++ ::  writing Binary Data On Txt File?

Aug 16, 2013

I a want to write a code to convert a string into binary data for that i wrote a code its working perfectly but there is one problem , some of the binary data is written in 7bit and i want to convert it to 8 bit by adding 0 to the last.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code]....

View 2 Replies View Related

C++ :: Pointers / Binary Data And Shifting

Sep 15, 2014

unsigned short foo = 1337;
//since unsigned short is 2 bytes, a char x[2]should be enough to hold the binary data
char foo2[2];

How do I have foo2, contain the binary equivalent of foo? (how can I point foo2 to = &foo)

View 4 Replies View Related

C :: Binary Search Tree - Struct Data

Oct 24, 2013

I was working with binary search tree and came up with the solution:

Code:
#include<stdio.h>
#include<stdlib.h>
typedef struct data {
int x;
struct data *left;
struct data *right;

[Code] .....

View 6 Replies View Related

C :: Writing Binary Data Or Reading From A File

Mar 6, 2013

I am having problems either writing data to a binary file or reading from the file. Through the process of elimination I am posting the code where the data is written to file to see if I can eliminate that as an option. I know the data is being processed correctly because, through the use of another function, I can view the data.

I also know that fwrite must be including some padding because the file size ends up being 576 bytes after it is written instead of 540 bytes (the size it would be if no padding is used). Here is my struct:

Code:

typedef struct {
char teams[25];
float wins;
float losses;
float pct;
int runsScored;
int runsAgainst;
} STATISTICS;

Here is where I initialize it:

Code:
STATISTICS stats[12] = {
{"Anaheim Arrays", 0.0, 0.0, .000, 0, 0},
{"Pittsburg Pointers", 0.0, 0.0, .000, 0, 0},
{"Indianapolis Integers", 0.0, 0.0, .000, 0, 0},

[Code] ....

And here is the function that writes my data. The sA array is only used to change the scheduled games based on the variable week.

Code:
void schedule(STATISTICS stats[]) {
FILE *f;
int sA[12], week = 0, runsPerGameA = 0, runsPerGameB = 0, runsAgainstA = 0, runsAgainstB = 0;
int index, a = 0, b = 1, i = 0;

[Code] .....

View 13 Replies View Related

C++ :: Create A Binary File Based On HEX Data

Apr 24, 2013

I want to create a binary file based on some hex data :

Ex Input Hex :54313032202020303030

Out put like :6      

View 2 Replies View Related

C++ :: Printing Data As It Is Stored In Memory (binary)?

Mar 21, 2013

So, if I'm right, computer store their data as binary values. So if I write int x = 5; , my computer converts the value of x from decimal (5) into binary (101) and stores it in memory as a a binary number. If I print that value on the screen that value is converted(by default) back into a decimal number before being printed on the screen.

Now, my question is if there is any way to print the value of x directly into binary(as it's stored in memory) without it being converted back into a decimal value?

View 10 Replies View Related

C++ :: Generate A Binary String Based On Hex Data

Apr 23, 2013

Generate a binary ascii characters(weird character ) based on Hex:54313032202020303030 data in C++

View 3 Replies View Related







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