Skip to main content
Filter by
Sorted by
Tagged with
5 votes
1 answer
127 views

This is a follow-up on: Why is it UB to pass a char array as the argument of placement new? The spec says the following for creating an object using an existing storage - [intro.object#3]: If a ...
Amir Kirsh's user avatar
  • 14.5k
2 votes
0 answers
60 views

I’m using ffi-napi and ref-napi in Node.js to call a C function, but I encountered the following error: TypeError: error setting argument 3 - writePointer: Buffer instance expected as third argument ...
lhy's user avatar
  • 31
2 votes
1 answer
101 views

I have a QString which stores a hashed input via the line hashedPass = QCryptographicHash::hash(input.toLocal8Bit(), QCryptographicHash::Sha256).toHex() I am trying to convert this code to an ...
Quintus's user avatar
  • 21
2 votes
1 answer
111 views

So I was playing around with char* and unsigned char* pointers. And I came across this issue: Code: #include <stdio.h> void func(unsigned int max) { unsigned int* intptr = &max; ...
programk5er's user avatar
0 votes
1 answer
50 views

I'm using C and stb_image, and image data is stored in an unsigned char* where a group of 4 elements represents a pixel, with r, g, b, and a channels respectively. I'm trying to get pixels of part of ...
Scollier's user avatar
  • 631
0 votes
2 answers
116 views

In this function, why do we need to cast with unsigned char? Can't we cast with char and get the same result since both have a range of "255"? Why choose unsigned char? Suppose there is no ...
NOURDDINE BENYAHYA's user avatar
0 votes
2 answers
170 views

This is the exercise that I'm doing: Assignment name : print_bits Expected files : print_bits.c Allowed functions: write Write a function that takes a byte, and prints it in binary WITHOUT A ...
Joao Pereira's user avatar
0 votes
1 answer
67 views

int main(){ int a, b; char *cp; a = 511; cp = &a; b = *cp; *cp = 10; printf("%d %d %d", a,b,*cp); return 0; } The output for the above code is 266 -1 10 ...
JoshuvaBernard's user avatar
3 votes
3 answers
1k views

In the below code snippet, why do we get an output of 600? Two questions will help me understand the behavior. I specified the type for variable b to be uint8_t, why doesn't the math operation ...
niil87's user avatar
  • 57
5 votes
1 answer
145 views

The following program: #include <iostream> #include <string> int main () { unsigned char result1 {0}; unsigned char result2 {0}; result1 = (result1 - 1) % 8; result2 = ...
JosF's user avatar
  • 153
0 votes
1 answer
776 views

I have the below program to convert my class into JSON object using Nlohmann JSON, When I used the std::array<unsigned char, SIZE> it gave an error, but when I used the std::array<char, SIZE&...
Piyush Malaviya's user avatar
0 votes
1 answer
659 views

I have this string. char * data = "A1B2C3D4E5F6A7B8"; Here each A1 B2 C3 D4 E5 F6 A7 B8 will be bytes for unsigned char* buffer. My concern is how to convert the data into unsigned char* ...
KKS's user avatar
  • 1,389
0 votes
1 answer
172 views

I've got a copy of the book "The C Programming Language", and in one of the first chapters it shows a short example of a code that copies characters from stdin to stdout. Here is the code: ...
noname delete's user avatar
0 votes
1 answer
451 views

#include<stdio.h> int main() { unsigned char a,b; printf("Enter first number : "); scanf("%d",&a); printf("Enter 2nd number : "); ...
Mohit Sharma's user avatar
-1 votes
1 answer
203 views

I have this struct with 2 attributes (one char and one int, for a memory usage of 3 bytes: struct Node { char data; int frequency; } I try overload the operators << and >> for ...
Kleber Mota's user avatar
  • 9,145
-5 votes
1 answer
701 views

#include <stdio.h> int main() { unsigned char c = (int) 0.54; for(; c++; printf("%d", c)); printf("%d", c); return 0; } And when I run the program the ...
Nishanthan Ravichandran's user avatar
0 votes
1 answer
62 views

I'm trying to fit my C++ app to a C-API. The API in question is mbed_tls which contains a base64 decoder: int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *...
glades's user avatar
  • 5,392
0 votes
0 answers
295 views

Suppose I have unsigned int x = 0x12a unsigned char y = 0x000 How can I make x = y? When I try to assign x to y, i get y = 0x02a
rickiestRick's user avatar
1 vote
1 answer
783 views

I have an text file called with the extension '.image', at the top of the file is the following: Image Type: unsigned char Dimension: 2 Image Size: 512 512 Image Spacing: 1 1 Image Increment: 1 1 ...
user avatar
-1 votes
3 answers
92 views

Can someone explain me how is this at the end a=?,b=?,c=-124 and not a=?,b=?,c=132 This is code: #include <stdio.h> int main() { char a = 'D', b='C', c='A'; a = c + 'D'; b = a + b + 'A'...
mr fahrenheit's user avatar
2 votes
5 answers
8k views

Hey I am kinda new to C and I wanted to ask why this prints out 4 instead of 260? #include <stdio.h> int main() { unsigned char x = 130; x *= 2; printf("%d\n", x); }
Alpha's user avatar
  • 329
1 vote
1 answer
124 views

The following code has several issues - for which I'm kindly asking for your input / corrections / feedback - of various types: first, I can't get it to do what I'd like to, namely pass it a "...
cg79's user avatar
  • 103
1 vote
0 answers
937 views

I'm trying to compile https://github.com/jbeder/yaml-cpp on a Raspberry Pi, and I'm getting this error: /home/pi/yaml-cpp/test/binary_test.cpp:11:38: error: narrowing conversion of ‘-58’ from ‘int’ to ...
OZ1SEJ's user avatar
  • 425
0 votes
0 answers
84 views

I writing a function that will print out hexadecimal inside unsigned char array. But I can't get the size of the array. I tried using sizeof() but it seems to print out the size of the type which is 4....
Nattapat's user avatar
1 vote
1 answer
946 views

I have the following piece of code: const unsigned char *a = (const unsigned char *) input_items; input_items is basically the contents of a binary file. Now a[0] = 7, and i want to convert this ...
Mobi Zaman's user avatar
0 votes
0 answers
28 views

Can anyone please tell me that why in signed char range -128 is equal to +128, -127 is equal to +129 and so on. Although in signed range 0 represents positive values most significant bit 1 reserved ...
Xinther3q3's user avatar
0 votes
2 answers
140 views

I am trying to learn image processing using c. #include <stdio.h> int main(){ FILE *streamIn; streamIn=fopen("lena512.bmp","r"); //read imageHeader and ...
Nishani Kasineshan's user avatar
0 votes
1 answer
277 views

I have inherited some C++ code that sets up a serial com port in Windows. The code contains the following declaration and method, which I have simplified for the purposes of this question. std::queue&...
jt1995SCO's user avatar
3 votes
2 answers
1k views

I have a function that takes as input an array of unsigned char (16 values exactly) and creates a GUID (from GUID struct) by parsing all values to hexadecimal and passing a guid-formatted string to ...
Uri Shapira's user avatar
1 vote
1 answer
715 views

Since unsigned char represents 0 - 255 and the extended ascii code for 'à' is 133, I expected the following C code to print 133 unsigned char uc; uc='à'; printf("%hhu \n",uc); Instead, ...
redwood_gm's user avatar
1 vote
0 answers
36 views

Even setting the size of an enum is not enough to be able to assign it to a variable of the same size (http://coliru.stacked-crooked.com/a/edd287393f172abd): #include <iostream> #include <...
vegalock's user avatar
1 vote
1 answer
314 views

I’m trying to cast the value 247 to a char in C++ (Visual Studio). I’m getting a Debug Assertion Failed error, saying unsigned(c+1) should be less than or equal to 256. I don’t understand where this ...
liz's user avatar
  • 11
0 votes
0 answers
319 views

I am attempting to prompt user input for a string of 32 characters (256 bits) to be read into an unsigned char array. I plan to use this unsigned char array for a 256 bit AES encryption key using ...
crok's user avatar
  • 1
1 vote
2 answers
2k views

My laptop runs a Python program that reads a joystick to send a speed command to an Arduino that in turn controls the motor on a toy car. To do that the program converts an integer with values between ...
Daanii's user avatar
  • 259
-2 votes
1 answer
997 views

Say for instance I have this unsigned long long int: unsigned long long int test_int = 0xcfffedefcfffeded; // 14987959699154922989 How could I convert test_int into the following unsigned char* array:...
mehmed_ali343's user avatar
0 votes
4 answers
3k views

Does anyone know of a library that provides a function that performs this logic or perhaps a method to perform this logic? I'm trying to convert: unsigned char test[] = "\x00\x00\x56\x4b\x7c\x8a\...
mehmed_ali343's user avatar
1 vote
1 answer
151 views

A char data type is not guaranteed to be signed, which means on some implementations it is signed, and on others it is unsigned. So why do people always ignore the signed qualifier? char c = 'C'; // ...
Maestro's user avatar
  • 2,572
-1 votes
1 answer
393 views

I have the following 2D vector: vector<vector<unsigned char>> dates; I also have the following unsigned char array: unsigned char date[3] = {1, 18, 108}; When I push_back this array to ...
brickbobed's user avatar
0 votes
1 answer
647 views

I have a 3rd party x.dll and an export function which is named as "GenerateKeyEx-in C". I do not have any additional info such as .lib, header etc. I have found the function parameters from ...
Katsazuka's user avatar
0 votes
2 answers
351 views

I am trying to figure out, how to use an unsigned char type of a variable inside a for loop, while not "breaking" out of range for unsigned char, which can vary form 0 to 255. main(void) ...
lucenzo97's user avatar
  • 126
3 votes
1 answer
315 views

I am trying to iterate over a single const unsigned char array and assign/convert each element to a new char array using typecasting, every thread I've read suggests using typecasting however it's not ...
coder_xlf's user avatar
1 vote
1 answer
553 views

I have a unsigned char array like this: unsigned char myArr[] = {100, 128, 0, 32, 2, 9}; I am using reinterpret_cast to covert it to const char* as I have to pass a const char* to a method. This ...
Purdgr8's user avatar
  • 33
0 votes
0 answers
53 views

int main(){ char *mem = malloc(sizeof(char)*10); for(size_t i = 0; i < 10; i++){ mem[i] = 0xFF; } for (size_t i = 0; i < 10; i++){ if(mem[i] == 0xFF){ ...
Kartik's user avatar
  • 41
0 votes
5 answers
797 views

So I have no idea why this behavior is observed: #include <stdio.h> int main() { unsigned char c; char d; scanf("%hhu", &d); printf("%c\n", d); ...
Aaryan BHAGAT's user avatar
0 votes
1 answer
837 views

In this code: vector<unsigned char> result; int n; unsigned char c; c = (n >> 24) & 0xFF; result.push_back(c); c = (n >> 16) & 0xFF; result.push_back(c); c = ...
Kleber Mota's user avatar
  • 9,145
2 votes
2 answers
1k views

I'm a bit troubled by this code: typedef struct _slink{ struct _slink* next; char type; void* data; } assuming what this describes is a link in a file, where data is 4bytes long ...
giorgioh's user avatar
  • 367
1 vote
0 answers
141 views

I have an array of unsigned chars ( unsigned char *), how can I convert it to a vector of unsigned chars? ( std::vector<unsigned char> )?
Kidsm's user avatar
  • 328
1 vote
1 answer
703 views

I'm trying to upload a file (.pak file) using fopen, read it and make it equal blockStorage. What I'm doing right now doesn't work, I think because pfile.data() doesn't even exist (it's left over from ...
Erasto Paula's user avatar
0 votes
1 answer
332 views

I have DLL written in C++. I need to use it in my C# code I am trying to make such object of C++ in C#: typedef struct { int width; int height; int stride; unsigned char *pixels;} FIS_Image; Does ...
Komiljon Aliyev's user avatar
3 votes
2 answers
679 views

When I write data to and from a buffer to save to a file I tend to use std::vector<unsigned char>, and I treat those unsigned chars just as bytes to write anything into, so: int sizeoffile = 16;...
Zebrafish's user avatar
  • 16.5k

1
2 3 4 5
7