char

In C, why is sizeof(char) 1, when 'a' is an int?

I tried printf("%d, %d\n", sizeof(char), sizeof('a')); and got 1, 4 as output. If size of a character is one, why does 'c' give me 4? I guess it's because it's an integer. So when I do char ch = 'c'; is there an implicit conversion happening, under the hood, from that 4 byte value to a 1 byte value when it's assigned to the char variab...

Java: Checking contents of char variable with if condition

Hello, I have a char variable that is supposed to contain either a Y,y,n or N character, I want to test if it does not contain it, then display an error message and exit the program. This is the code I am using; if (userDecision != 'Y' || userDecision != 'y' || userDecision != 'n' || userDecision != 'N') { Syste...

Is the MsComm ActiveX compatible with Delphi 2010?

I have ported our project from Delphi 7 to Delphi 2010. After adding some type casts now my project is running well and all the features work correctly except main functionality of the program which is bound to COM ports and the MSCOMM ActiveX component. It can read and write from a COM port but it seems something is wrong with that bec...

Why not DriverManager.getConnection(String url, String user, char[] password)?

We know it's a good practice to prefer char[] over java.lang.String to store passwords. That's for the following two reasons (as I have read): char[] are mutable so we can clear the passwords after the usage. String literals goes to a pool that will not get garbage collected as other objects, hence might appear in memory dumps. But j...

how to grow a dynamic array of char pointers (in C++)?

I am trying to work with an array of char pointers. Let's say I dynamically declare such an array like so: int numrows=100; char** array = new char*[numrows]; And then I populate it by using getline to get strings from a file, converting the strings to char arrays, then setting a pointer in my array to point to said char array l...

Convert numbers with toString in Ansi C

Is it possible to use toString operator, or how to convert numbers to char arrays. ...

Copy const char*

Hello, I'm receiving a c-string as a parameter from a function, but the argument I receive is going to be destroyed later. So I want to make a copy of it. Here's what I mean: class MyClass { private: const char *filename; public: void func (const char *_filename); } void MyClass::func (const char *_filename) { filename = _filenam...

C++: How to build Strings / char*

Hi, I'm new to C++. I want to make a char*. But I don't know how. In Java is it just this: int player = 0; int cpu = 0; String s = "You: " + player + " CPU: " + cpu; How can I do this? I need a char*. Where I'm focusing on is to paste the integer after the string. Edit: I want to use a method that takes an argument char *, so if...

How to convert string to char in C

I'm writing a compiler in C and need to get the ASCII value of a character defined in a source code file. For normal letters this is simple but is there any way to convert the string "\n" to the ASCII number for '\n' in C (needs to work on all characters)? Cheers ...

Random int 1-255 to character in C

I have a function that returns an integer, between 1 and 255. Is there a way to turn this int into a character I can strcmp() to an existing string. Basically, I need to create a string of letters (all ASCII values) from a PRNG. I've got everything working minus the int to char part. There's no Chr() function like in PHP. ...

Allocating memory for a char array to concatenate a known piece of text and an integer

I want to concatenate a piece of text, for example "The answer is " with a signed integer, to give the output "The number is 42". I know how long the piece of text is (14 characters) but I don't know how many characters the string representation of the number will be. I assume the worst case scenario, the largest signed 16-bit integer ...

C char to string (passing char to strcat())

hi all, my problem is in convert a char to string i have to pass to strcat() a char to append to a string, how can i do? thanks! #include <stdio.h> #include <string.h> char *asd(char* in, char *out){ while(*in){ strcat(out, *in); // <-- err arg 2 makes pointer from integer without a cast *in++; } return out;...

Function to prevent special characters in nickname

Hi, I've a website where users can register. I would like to prevent all special characters, accents, etc in the nickname (used to login). I use PHP. How can I do that ? Edit: Another question, can you give me a regular expression (in PHP) who allow ONLY the 26 letters : abcdefghijklmnopqrstuvwxyz and no more ? Thanks ...

char '0x8' what character is this?

I have a large amount of data in a database. When I attempt to read a certain portion of the data and generate some xml and send it to a webservice I get the following exception... The char '0x8' in 'java.lang.IllegalArgumentException'. I'm guessing it is some bad data, as it has worked perfectly for about 7 months but now some user...

JNA problem with char** (in dll)

Hi, ok it is 'easy' to make jna wrapper solution for mapping exported functions within dll using jna: long f1(int x), just int long f2(char* y), just char[] but how to deal with long f3(char** z) ? I need f3's result(long) as well as z value on java side. Please don't say cpp code should be rewritten to avoid this:-) ...

_T("x") not acting as it should.

Hi, I am running into lots of problems with Unicode at the moment. As I understand it, TCHAR is defined to be either a wchar_t or a char depending on whether _UNICODE is defined somewhere, and there are various other functions to help with this. Apparently _T("x") should evaulate 'x' to either a wchar_t or a char depending on how stuff ...

Signedness of char and Unicode in C++0x

From the C++0x working draft, the new char types (char16_t and char32_t) for handling Unicode will be unsigned (uint_least16_t and uint_least32_t will be the underlying types). But as far as I can see (not very far perhaps) a type char8_t (based on uint_least8_t) is not defined. Why ? And it's even more confusing when you see that a ...

Counting Alphabetic Characters That Are Contained in an Array with C

Hello everyone, I am having trouble with a homework question that I've been working at for quite some time. I don't know exactly why the question is asking and need some clarification on that and also a push in the right direction. Here is the question: (2) Solve this problem using one single subscripted array of counters. The pro...

In Java how does one turn a String into a char or a char into a String?

Is there a way to turn a char into a String or a String with one letter into a char (like how you can turn an int into a double and a double into an int)? (please link to the relevant documentation if you can). How do I go about finding something like this that I'm only vaguely aware of in the documentation? ...

why does a char + another char = a weird number

Here's the code snippet: public static void main (String[]arg) { char ca = 'a' ; char cb = 'b' ; System.out.println (ca + cb) ; } The output is: 195 Why is this the case? I would think that 'a' + 'b' would be either "ab" , "12" , or 3. Whats going on here? ...