Questions tagged [char]

char refers to the character data-type, representing letters, digits, punctuation marks, control characters, etc. Use this tag for questions relating to and usage of the character data-type.

The keyword char is used in many programming languages, often defining a 1-byte memory location representing ASCII, UTF-8, UTF-16, UTF-32, and ISO-8895-1 character encodings. Arrays of characters can create Strings used to form words, descriptive text, or even extremely large numbers unable to be represented exactly by 32 or 64 bits.

13281 questions
149
votes
9 answers

Escape Character in SQL Server

I want to use quotation with escape character. How can I do to avoid the following error when one has a special character? Unclosed quotation mark after the character string.
esquare
  • 3,947
  • 10
  • 34
  • 37
142
votes
24 answers

Take a char input from the Scanner

I am trying to find a way to take a char input from the keyboard. I tried using: Scanner reader = new Scanner(System.in); char c = reader.nextChar(); This method doesn't exist. I tried taking c as a String. Yet, it would not always work in every…
Ralph
  • 2,959
  • 9
  • 26
  • 49
138
votes
11 answers

How to do scanf for single char in C

In C: I'm trying to get char from the user with scanf and when I run it the program don't wait for the user to type anything... This is the code: char ch; printf("Enter one char"); scanf("%c", &ch); printf("%c\n",ch); Why is not working?
Yuval
  • 1,721
  • 4
  • 16
  • 15
131
votes
4 answers

What is the purpose of a unary "+" before a call to std::numeric_limits members?

I saw this example in cppreference's documentation for std::numeric_limits #include #include int main() { std::cout << "type\tlowest()\tmin()\t\tmax()\n\n"; std::cout << "uchar\t" <<…
Zhang
  • 3,030
  • 2
  • 14
  • 31
119
votes
11 answers

How to check if a char is equal to an empty space?

Here's what I've got: private static int countNumChars(String s) { for(char c : s.toCharArray()){ if (Equals(c," ")) } } But that code says it cannot find Symbol for that method. I remember Java having a comparer like this... Any…
delete
118
votes
7 answers

How can I increment a char?

I'm new to Python, coming from Java and C. How can I increment a char? In Java or C, chars and ints are practically interchangeable, and in certain loops, it's very useful to me to be able to do increment chars, and index arrays by chars. How can I…
Tom R
  • 5,991
  • 9
  • 35
  • 41
117
votes
16 answers

clearing a char array c

I thought by setting the first element to a null would clear the entire contents of a char array. char my_custom_data[40] = "Hello!"; my_custom_data[0] = '\0'; However, this only sets the first element to null. or my_custom_data[0] = 0; rather…
ant2009
  • 27,094
  • 154
  • 411
  • 609
117
votes
7 answers

Removing "NUL" characters

I have got characters like that in my notepad++ When i am trying to copy whole line, i am actually copying everything until "NUL": File:1 What i want to do, is replace those null, to be nothing, so i can copy my whole line. Maybe there is any…
user2618929
  • 1,591
  • 4
  • 13
  • 14
116
votes
11 answers

Why are C character literals ints instead of chars?

In C++, sizeof('a') == sizeof(char) == 1. This makes intuitive sense, since 'a' is a character literal, and sizeof(char) == 1 as defined by the standard. In C however, sizeof('a') == sizeof(int). That is, it appears that C character literals are…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
111
votes
3 answers

Are there machines, where sizeof(char) != 1, or at least CHAR_BIT > 8?

Are there machines (or compilers), where sizeof(char) != 1? Does C99 standard says that sizeof(char) on standard compliance implementation MUST be exactly 1? If it does, please, give me section number and citation. Update: If I have a machine (CPU),…
osgx
  • 90,338
  • 53
  • 357
  • 513
108
votes
14 answers

How to copy a char array in C?

In C, I have two char arrays: char array1[18] = "abcdefg"; char array2[18]; How to copy the value of array1 to array2 ? Can I just do this: array2 = array1?
user2131316
  • 3,111
  • 12
  • 39
  • 53
106
votes
13 answers

How to empty a char array?

Have an array of chars like char members[255]. How can I empty it completely without using a loop? char members[255]; By "empty" I mean that if it had some values stored in it then it should not. For example if I do strcat then old value should not…
Alex Xander
  • 3,903
  • 14
  • 36
  • 43
105
votes
14 answers

What's the default value of char?

char c = '\u0000'; When I print c, it shows 'a' in the command line window. So what's the default value of a char type field? Someone said '\u0000' means null in Unicode; is that right?
user1298336
  • 1,075
  • 2
  • 8
  • 6
104
votes
16 answers

Convert hex string (char []) to int?

I have a char[] that contains a value such as "0x1800785" but the function I want to give the value to requires an int, how can I convert this to an int? I have searched around but cannot find an answer. Thanks.
kizyle502
  • 1,059
  • 2
  • 8
  • 4
102
votes
10 answers

How can non-ASCII characters be removed from a string?

I have strings "A função", "Ãugent" in which I need to replace characters like ç, ã, and à with empty strings. How can I remove those non-ASCII characters from my string? I have attempted to implement this using the following function, but it is not…
rahulsri
  • 2,711
  • 4
  • 16
  • 11