unsigned-char

Is the signedness of char an interface issue?

北战南征 提交于 2019-12-12 12:12:53
问题 Suppose I have a function void foo(char *) which, internally, needs to treat its input as a block of NUL-terminated bytes (say, it's a hash function on strings). I could cast the argument to unsigned char* in the function. I could also change the declaration to void foo(unsigned char *) Now, given that char , signed char and unsigned char are three different types, would this constitute an interface change, under any reasonable definition of the term "interface" in C? (This question is

Reading text from file to unsigned char array, errors while trying to use example [closed]

☆樱花仙子☆ 提交于 2019-12-12 03:46:00
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I'm trying to use example from: https://stackoverflow.com/a/6832677/1816083 but i have: invalid conversion from `unsigned char*' to `char*' initializing

Debug Assertion Failed File, tokenScanner, and text files

馋奶兔 提交于 2019-12-11 19:14:36
问题 I have written a program that processes text files one at a time and extract relevant information. My program works well with some of the text files and not others. There is no obvious difference between the files that run seamlessly through my program and those that don't. As far as the problematic files are concerned: the program opens the file it reads in and processes a good chunk of the lines one at a time as it should But then it reaches a problem line and gives the error message:

C++ iostream >> operator behaves differently than get() unsigned char

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 06:45:24
问题 I was working on a piece of code to do some compression, and I wrote a bitstream class. My bitstream class kept track of the current bit we are reading and the current byte (unsigned char). I noticed that reading the next unsigned character from the file was done differently if I used the >> operator vs get() method in the istream class. I was just curious why I was getting different results? ex: this->m_inputFileStream.open(inputFile, std::ifstream::binary); unsigned char currentByte; this-

Converting char* to unsigned char array C

余生长醉 提交于 2019-12-11 03:06:47
问题 I am reading a file that has some data in it. The data is not uniform. But once in a while there might be a line that have a file name and SHA1 sum value in it. I read the data line by line, and then when there is a line with SHA1 sum value, I use strtok, to get data in tokens. And I get SHA1 sum in a variable (e.g: char *hash). Later in the program, I re-run SHA1 on the same file to get the hash sum (in a variable such as unsigned char hash[20]). Now I want to compare these to values, but I

Minimally invasive change for strchr on unsigned char * in C++ from a C codebase?

荒凉一梦 提交于 2019-12-11 01:53:51
问题 I'm trying to compile a C codebase as C++, tweaking some of the includes. It uses strchr() on unsigned char pointers, e.g.: #include <string.h> #include <stdio.h> // Cannot modify this file with any non-C-isms, but let's say an include can // be changed (although all things being equal I'd rather not) #include <SomethingICanChange.h> int main(int argc, char* argv[]) { unsigned char b = 'B'; unsigned char const * str = "ABC"; unsigned char const * pos = strchr(str, b); if (pos) { printf(

Difference between unsigned char and char pointers

不羁的心 提交于 2019-12-10 16:07:08
问题 I'm a bit confused with differences between unsigned char (which is also BYTE in WinAPI) and char pointers. Currently I'm working with some ATL-based legacy code and I see a lot of expressions like the following: CAtlArray<BYTE> rawContent; CALL_THE_FUNCTION_WHICH_FILLS_RAW_CONTENT(rawContent); return ArrayToUnicodeString(rawContent); // or return ArrayToAnsiString(rawContent); Now, the implementations of ArrayToXXString look the following way: CStringA ArrayToAnsiString(const CAtlArray<BYTE>

std::move between std::string and std::vector<unsigned char>

余生长醉 提交于 2019-12-10 12:34:57
问题 I am working with 2 libraries. One takes in and returns std::string s while the other uses std::vector<unsigned char> s. It would be good if I could steal the underlying arrays from std::string and std::vector<unsigned char> and be able to move them into each other without the excessive copying. ATM I use something like: const unsigned char* raw_memory = reinterpret_cast<const unsigned char*>(string_value.c_str()), std::vector<unsigned char>(raw_memory, raw_memory + string_value.size(); And

Invalid conversion from unsigned char* to char*

醉酒当歌 提交于 2019-12-10 01:36:44
问题 Here is a code - 1 int main(int argc, char *argv[]) 2 { 3 signed char S, *psc; 4 unsigned char U, *pusc; 5 char C, *pc; 6 7 C = S; 8 C = U; 9 10 pc = psc; 11 pc = pusc; 12 13 return 0; 14 } $ gcc test.cpp -o a test.cpp: In function ‘int main(int, char**)’: test.cpp:10:7: error: invalid conversion from ‘signed char*’ to ‘char*’ [-fpermissive] test.cpp:11:7: error: invalid conversion from ‘unsigned char*’ to ‘char*’ [-fpermissive] This is compiled on gcc version 4.6.3 on Ubuntu 12.10 on an

C++ - Allocate an unsigned char buffer and then fill it with a string

一曲冷凌霜 提交于 2019-12-06 12:12:04
I am realively new to C++ so please forgive me if this is a naive question - but I'm stuck on finding an answer. I am trying to create an unsigned char array of size 1024 which I have done with the following code: unsigned char *r_record = new unsigned char[1024](); Now I have an std::string variable: std::string hw = "Hello Word"; And I would like to populate the r_record with hw (i.e., 'Hello World') starting at the 10'th byte. How can I place hw into r_record ? So in effect, my r_record data would look like (where the . 's are empty): [.........Hello World......and so on] You can use std: