char

How do I convert a single char in string to an int

Keep in mind, if you choose to answer the question, I am a beginner in the field of programming and may need a bit more explanation than others as to how the solutions work. Thank you for your help. My problem is that I am trying to do computations with parts of a string (consisting only of numbers), but I do not know how to convert a...

Const unsigned char* to char*

So, I have two types at the moment: const unsigned char* unencrypted_data_char; string unencrypted_data; I'm attempting to perform a simple conversion of data from one to the other (string -> const unsigned char*) As a result, I have the following: strcpy((unencrypted_data_char),(unencrypted_data.c_str())); However, I'm receiving ...

Why is the Objective-C Boolean data type defined as a signed char?

Something that has piqued my interest is Objective-C's BOOL type definition. Why is it defined as a signed char (which could cause unexpected behaviour if a value greater than 1 byte in length is assigned to it) rather than as an int, as C does (much less margin for error: a zero value is false, a non-zero value is true)? The only re...

initializing char and char pointers

What's the difference between these: This one works: char* pEmpty = new char; *pEmpty = 'x'; However if I try doing: char* pEmpty = NULL; *pEmpty = 'x'; // <---- doesn't work! and: char* pEmpty = "x"; // putting in double quotes works! why?? EDIT: Thank you for all the comments: I corrected it. it was supposed to ...

Question about memory allocation when initializing char arrays in C/C++.

Before anything, I apologize if this question has been asked before. I am programming a simple packet sniffer for a class project. For a little while, I ran into the issue where the source and destination of a packet appeared to be the same. For example, the source and destination of an Ethernet frame would be the same MAC address all o...

Multiply char by integer (c++)

Is it possible to multiply a char by an int? For example, I am trying to make a graph, with *'s for each time a number occurs. So something like, but this doesn't work char star = "*"; int num = 7; cout << star * num //to output 7 stars ...

Scanner method to get a char

What is the Scanner method to get a char returned by the keyboard in Java. like nextLine() for String, nextInt() for int, etc. ...

Separating null byte separated UNICODE C string.

First off, this is NOT a duplicate of: http://stackoverflow.com/questions/1911053/turn-a-c-string-with-null-bytes-into-a-char-array , because the given answer doesn't work when the char *'s are Unicode. I think the problem is that because I am trying to use UTF-8 encoded char *'s instead of ASCII char *'s, and the length of each charact...

C# assign char and char array to string?

char character = 'c'; string str = null; str = character.ToString();//this is ok char[] arrayChar = { 'a', 'b', 'c', 'd' }; string str2 = null; str2 = string.Copy(arrayChar.ToString());//this is not ok str2 = arrayChar.ToString();//this is not ok. I'm trying to converting char ar...

How do I convert integers to characters in C#?

I am trying to convert an index of 1 to 27 into the corresponding uppercase letter. I know that in C++ I could type this: char letter = 'A' + (char)(myIndex % 27); This same code does not work in C#. How can I accomplish this task in C#? EDIT: I'd rather not have to encode an enum or switch statement for this if there is a better mat...

How do I convert from unicode to single byte in C#?

How do I convert from unicode to single byte in C#? This does not work: int level =1; string argument; // and then argument is assigned if (argument[2] == Convert.ToChar(level)) { // does not work } And this: char test1 = argument[2]; char test2 = Convert.ToChar(level); produces funky results. test1 can be: 49 '1' while test2...

C++ using cdb_read returns extra characters on some reads

Hi All, I am using the following function to loop through a couple of open CDB hash tables. Sometimes the value for a given key is returned along with an additional character (specifically a CTRL-P (a DLE character/0x16/0o020)). I have checked the cdb key/value pairs with a couple of different utilities and none of them show any addit...

SQL Better performance: char(10) and trim or varchar(10)

I have a database that uses codes. Each code can be anywhere from two characters to ten characters long. In MS SQL Server, is it better for performance to use char(10) for these codes and RTRIM them as they come in, or should I use varchar(10) and not have to worry about trimming the extra whitespace? I need to get rid of the whitespace...

C++: Should I use strings or char arrays, in general?

I'm a bit fuzzy on the basic ways in which programmers code differently in C and C++. One thing in particular is the usage of strings in C++ over char arrays, or vice versa. So, should I use strings or char arrays, in general, and why? ...

How to Find and Replace the Enter character?

How to Find and Replace the 'Enter' characters in the text file? Here is my code: string searchString( "\r" ); // <------- how to look for ENTER chars? string replaceString( "XXXX" ); assert( searchString != replaceString ); string::size_type pos = 0, pos3 =0; while ( (pos = test.find(searchString, pos)) != string::npos ) { tes...

Beginner C++ Question

I have followed the code example here toupper c++ example And implemented it in my own code as follows void CharString::MakeUpper() { char* str[strlen(m_pString)]; int i=0; str[strlen(m_pString)]=m_pString; char* c; while (str[i]) { c=str[i]; putchar (toupper(c)); i++; } } But this gives me the following compiler...

how can i store more than just one letter in a variable?

with char i get this error: .\main.cpp(6) : error C2015: too many characters in constant ...

Address of array vs. address of array[0] - C language

My question is why does the address of an array differ from the address of its first position? I'm trying to write my own malloc, but to start out I'm just allocating a chunk of memory and playing around with the addresses. My code looks roughly like this: #define BUFF_SIZE 1024 static char *mallocbuff; int main(){ mallocbuff = ...

std::cin >> *aa results in a bus error

I have this a class called PPString: PPString.h #ifndef __CPP_PPString #define __CPP_PPString #include "PPObject.h" class PPString : public PPObject { char *stringValue[]; public: char *pointerToCharString(); void setCharString(char *charString[]); void setCharString(const char charString[]); }; #endif PPString.cpp...

How do I use multiple precisions in printf()?

Looking at the information under the heading "Precision can be omitted or be any of:". The example: printf("%.*s", 3, "abcdef"); works, outputting:abc (truncating the rest of the string.) Now, I would like to have a string with multiple parameters formatted (truncated): printf("%.*s, %.*s", 3, 3, "abcdef", "xyz123"); but the progra...