C :: Int Array To Char (Binary Value)

Jul 19, 2013

I have an int array with the binary value of a char. How to to turn it into a char? I can transform it to an int but then I'm stuck.

Code:
#include <stdio.h>
int main() {
int a[260] = {0,1,1,0,0,0,0,1};
char buf[260];
int b=0;
for(int i=0; i<8; i++) {
b=10*b+a[i];
}
itoa(b, buf, 10);

View 6 Replies


ADVERTISEMENT

C++ :: Encrypt Char Array With Binary Data

Apr 14, 2013

I am trying to encrypt a char Array with binary data.

I think I understand the basic of Encryption / Decryption but I fail to see how to implement something.

I am trying to have a "key" that needs entered so the data can become readable executable. The program I am encrypting is a small console window with a message with the text "A secret message from your friend" (Not that it matters).

I have the binary data witch I can copy and what not. But how go about Encryption and then decrypt it and not destroying the data.

View 6 Replies View Related

C++ :: Binary Char Pointer Into String

Jun 12, 2013

Is there a more simple method to copy Buf into str? Buf is a binary string.

Code:
void function(string & str) {
int iWholeSize = 512;
char * Buf = new char[iWholeSize];
.... operations on Buf
string s(Buf, Buf + iWholeSize);
str = s;
}

View 5 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++ :: Comparing Char Array To Char Always Returns True

Dec 23, 2014

I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.

this is the entire code:

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

[Code]....

at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.

View 4 Replies View Related

C++ :: Concatenate Two Char Arrays Into Single Char Array?

Sep 29, 2014

I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.

/* this is my terminal readout
joe bob
<- nothing is put into (*playerPtr).name, why not?
joe bob joe bob
seg fault*/
/****************************************************************/
//This is here to show my struct/playerInit

[Code]....

View 2 Replies View Related

C :: Char Array With A Phrase To Char Word

Nov 28, 2013

I need to do a function that copy every word from a text to a char word. How can i do it?

View 5 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 :: Parsing Char Array To Array Of Struct To Process Packets

May 28, 2013

I wrote this simplified version of a program i am writing that parses data in UDP packets. In the process of doing so i pretty much answered all my questions and fix all the problems i was having.

decodeSystemMap function will be in loop, and will proccess packets that have mostly the same data, only a few items will be added or changed or deleted.

whats the best way to check if there are any new, deleted, or removed items in the packet and only modify those?
Is there anything unsafe / dangrous about the way the code is now?

Code:
/* * File: main.c
* Author: david
*
* Created on May 23, 2013, 11:57 AM
*/

#include <stdio.h>
#include <stdlib.h>

[Code] ....

View 4 Replies View Related

C++ :: Convert Uint8 Array To Unsigned Char Array?

Mar 2, 2012

I have the following code which attempts to assign a u_int8 array of 256 to an unsigned char[256]:

Code:
unsigned char testData[256]=pSample->data;

I get the compilation error:

error C2440: 'initializing' : cannot convert from 'const uint8_t [256]' to 'unsigned char [256]'

What is the safe way to cast or convert here?

View 3 Replies View Related

C++ :: Convert Binary Search With Int Array To Use String Array

May 8, 2014

I'm having trouble converting this binary search with an int array to use a string array..

Code:

#include <iostream>
#include <string>
using namespace std;
// Function prototype
int binarySearch(string [], int);

[Code] .....

View 3 Replies View Related

C :: How To Convert Char Array Into Int Array

Jan 24, 2013

I am writing code to multiply two int arrays and in my one function i am trying to convert the char array into an int array. I have tested many parts however i can not find the problem.

Code:

struct integer* convert_integer(char* stringInt){
struct integer *converted = malloc(sizeof(struct integer));
int length, i, *ints;
ints = (int *)malloc(10001 * sizeof(int));
length = strlen(stringInt);
printf("stringInt: %s with length of %d
", stringInt, length);
converted->size = length;

[Code]...

View 5 Replies View Related

C++ :: Get Word From Char Array

Jan 28, 2015

Let's say i have some text in char array Code: char text[] = "Hello my friend"; How can i get a seperate words from it? It should be like

Code:
char a[] = "Hello";
char b[] = "my";
char c[] = "friend";

Is it possible to do?

View 2 Replies View Related

C :: Unable To Set Char Array

May 5, 2013

Code:

#include <stdio.h>
char * strcpy(char *restrict s1, const char *restrict s2);
struct item {
char title[20];
struct item *next;
} firstCard;
int main (){
strcpy(firstCard.next->title, "whatever");
}

I am unable to set firstCard.next->title

View 2 Replies View Related

C++ :: Char Array To String

Oct 19, 2013

I have some code:

char cHomeTeamFaceOffsPercentageWon[100];
memcpy(cHomeTeamFaceOffsPercentageWon,cSqlHomeTeamFaceOffsPercentageWon,100);

After this, for example, cHomeTeamFaceOffsPercentageWon is, "29%".

Then, I use

std::string szwPercentageWon = std::string(cHomeTeamFaceOffsPercentageWon);

szwPercentageWon is then, "2". Shouldn't this convert correctly, to "29%" as well.

Or is there something I'm missing? Maybe the termination character, or something.

View 1 Replies View Related

C++ :: Using A Pointer To Char Array

Aug 31, 2013

I like to use a Pointer to char array. And then I would like to do a Pointer Arithmetic by incrementing the Pointer. Finally I would like to see the Addresses of the Pointer to each of the char Array Elements. I had created a program below, but I am not getting any Addresses from my Pointer.

#include <iostream>
using namespace std;
int main () {
int ArraySize;
char ch[]= "This is a Char Pointer";
char* iPtr = ch;

[Code] ....

View 3 Replies View Related

C++ :: Array Of Char - Shows More Than It Should

Nov 9, 2013

I have this code:

#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
ifstream f("input.txt");
ofstream g("output.txt");

[Code] .....

This program make a copy of the source array, then it removes each character and shows the obtained array.

And when i insert "abcdefghijkl"

it should show this: "

#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
ifstream f("input.txt");
ofstream g("output.txt");

[Code] .....

View 1 Replies View Related

C/C++ :: Comparing 2D Char Array?

Jun 22, 2014

I am working on a program to find uppercase, lowercase and digits in a 2D char array. When I try to use an if statement to increase the counter, I get an error "no conversion from 'int' to 'char*'". This is the if statement I am using.

if(myArray[j] <='9' || myArray[j] >='0')

View 7 Replies View Related

C++ :: Assigning Char To Array?

Aug 7, 2014

I want to assign a char to an array inside an if statement after the user has input the grade as an integer, but it has to fill an array with characters, such as:

char grades[5];
int grade;
char A, B, C, D, F;
cout << "Enter da grade" << endl;
cin >> grade;
if (grade < 59) {
grade[0] = F;

[code]....

A, B, C, D, and F won't transfer to the array, thus giving me the uninitialized variable error in microsoft visual studio 2010.

View 4 Replies View Related

C++ :: Convert Int To Char Array

Jun 7, 2012

I want to convert int to char array for get the total of digits like this..

Code:

int total;
char charnum[2] = (char)total; //this is the problem
int num = 0;
for (int i = 0; i <2; i++)
{ num += charNum[i] -48;}
cout << num;

If total was 42 i want to get output as 6. for this purpose i want to convert int to char.

View 7 Replies View Related

C++ :: Char Array Initialization And Display

May 16, 2013

The following is something I am not clear about. Multi dimensional char arrays and the displaying of them.

Code:
#include <iostream>
using namespace std;
main() {
//char test[5][5]

[Code] .....

The commented out expression didn't run at all but the double quotation mark one did, unfortunately, it gives me a hexadecimal display. How can I get it to display like this:

*****
*****
*****
*****
*****

View 5 Replies View Related

C :: Find The Length Of Char Array

Sep 25, 2014

I am working on a c-programm. In this program I have to convert the amount of money I read on two variables into the corret format. I got Euros and cents on 2 ints. But now I want to add both of those variables in a String (char array). Also i want to find out the length of the new char array.

View 2 Replies View Related

C++ :: Converting String To Char Array

Mar 30, 2014

In this program, I have to ask the user for an employee, then the program will check to see if the file for that employee exist, if it doesnt then it will automatically create the file.

ReadNew function reads the file....check to see if it exist

CreateNew function creates a new file.

In my code I have no problem with the first part of reading file.. and my createnew function works in other programs where I am asking for input of file name to create the file name. However in this code I cannot figure how to automatically pass the input filename from the ReadNew function to the CreateNew function. I can't ask the user to enter the name a second time, so I have to pass the input filename into both functions. Here is my code.

Code:

//Create a file, append to it, and read it.
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
using namespace std;
char filename[256];
string n;
string filelist;
void CreateNew(ofstream & FileNew);

[Code]...

View 1 Replies View Related

C :: Pointer To A Char Inside Array

Jun 7, 2013

Alright, so I have a code that's not giving me errors, but it doesn't seem to retain what I put into an array. Not sure If I'm missing something...

Code:
#include <stdio.h>
int main (void)
{
const char *pointer;
const char alphabet[] = "ABCDEFG";

pointer = &alphabet[5];
printf("pointing to %c of the alphabet
", pointer);
return 0;
}

Trying to get my pointer to return the letter in the [5] spot or "F". Not receiving any errors when compiling, but I seem to get different answers every time I run it.

View 5 Replies View Related

C :: How To Output A Char Array And Typecasting

Jan 1, 2014

Code:
#include main() { char why[64]; why =255,255,255,255,255,255,255,255;
while (why > 4); printf("why is equal to" ,why); why = why-2;
return 0;
}

It tells me incompatible data type.

View 9 Replies View Related

C :: Returning Char Array By Function

Mar 2, 2015

I'm having trouble returning a char array by a function, here's the code. The problem is the 'reverse' function, the purpose of the function is to send two char arrays, 'newline' containing the char array, reverse it and place it in the 'rev' char array then output it back in main, however the output remains blank so I assume there must be something wrong with the reverse function.

Code:
#include <stdio.h>
#define MAXLINE 10
int fgetline(char line[], int maxline);
void copy(char to[], char from[]);
void reverse(char forw[], char rev[], int arrsize);

[Code] .....

View 1 Replies View Related







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