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
3
votes
2 answers

How does C know how long a char* is after assignment?

I know that there are two ways to use 'strings' in C-- char foo[NUMBER] = "bar"; char *foo = "bar"; I also know that, due to the way C stores the former, they are immutable--I can't reassign a new string to the array. So to have a mutable string…
Ben Granger
  • 481
  • 6
  • 19
3
votes
3 answers

Appending a char w/ null terminator in C

perhaps a lil trivial, but im just learning C and i hate doing with 2 lines, what can be done with one(as long as it does not confuse the code of course). anyway, im building strings by appending one character at a time. im doing this by keeping…
avcJav
  • 317
  • 3
  • 10
3
votes
2 answers

What character set does C's "char" use?

Simple question: I have recently started programming in C and have a simple question. What character set does the C programming language use in its "char" type, e.g ASCII, or does it depend on the software/operating system?
Bongani Dube
  • 78
  • 10
3
votes
2 answers

Is it guaranteed that size_t, vector::size_type, etc typedefs won't bind to a char type?

It is definitely possible that cstdint typedefs bind to char variables. For example, it is very likely that uint_least8_t binds to unsigned char, and int_least8_t binds to signed char. Does the Standard guarantee that similar thing won't happen to…
user4385532
3
votes
1 answer

Print the word (from user input) with the max amount of characters python

so the objective of this exercise is simple but I'm stuck. The program should take a list from user input (eg. tomatoes, fish, milk, watermelons...) and print the longest word in the list. So far I'm only able to print the amount of characters in…
3
votes
3 answers

subtracting characters of numbers

I am trying to understand what is going on with the code: cout << '5' - '3'; Is what I am printing an int? Why does it automatically change them to ints when I use the subtraction operator?
MS535
  • 47
  • 4
3
votes
3 answers

C string removal - how does this code work?

I have a working piece of C code that completely removes every second char from a character array, making the original array half the size (half+1 if the size was odd) ..but I cannot figure out how it works. void del_str(char string[]) { int…
zopad
  • 33
  • 4
3
votes
2 answers

How to convert gchar* to char

When I press a key(integer) on my keyboard. It does something like: gchar *keypressed; keypressed=gdk_keyval_name (event->keyval); printf("The KeyEvent is: %s\n", keypressed); // Till here it is fine I get segmentation fault when I do…
djgharphalia07
  • 227
  • 3
  • 14
3
votes
6 answers

How to count the occurrence of each character in char array?

I'm trying to count the occurrence of each character in an char array. How many times a specific lower case or upper case letter appears? What would be an effective method as I keep running in circles and into errors? This is the code I used to…
KingKrypton
  • 65
  • 1
  • 1
  • 5
3
votes
3 answers

How to assign values to const char* array and print to screen

Although I am using C++, as a requirement I need to use const char* arrays instead of string or char arrays. Since I am new, I am required to learn about how to use const char*. I have declared my const char* array as const char* str[5]. At a later…
jshapy8
  • 1,983
  • 7
  • 30
  • 60
3
votes
2 answers

Adding char as many times as a number

So I need to make a program that has the user input a height and output the following shape with nested loops: * * * * * * * * * * * * * * * * * * * * * * * * * My idea to get this to work is to use a char as a black space…
3
votes
2 answers

Character Shuffler

I was just wondering if there's a way (using ASP.NET C#) to "shuffle" up the contents of a string, but still be able to click another button and "UNshuffle" it back to its original content withOUT saving the original content? Thank you…
anon271334
3
votes
4 answers

Why C++ variable doesn't need defining properly when it's a pointer?

I'm completely new to the C++ language (pointers in particular, experience is mainly in PHP) and would love some explanation to the following (I've tried searching for answers). How are both lines of code able to do exactly the same job in my…
Jamie Cole
  • 51
  • 4
3
votes
1 answer

How to turn a char to upper case in java without using String

Is there an easier way to do this? public static void main(String[] args) { char x = 'a'; //If 'a' I want 'A', if 'z' i want 'Z', and so on. String aux = ""; aux=""+x; aux=aux.toUpperCase(); x=aux.charAt(0); }
Pablito
  • 197
  • 4
  • 16
3
votes
1 answer

Why does adding an int to this char array not add the ASCII character of the same value?

I've been working on a URLdecode function so I can parse POST requests received on an HTTP server, however I've ran into a hiccup. Whenever I add an integer to an array, it is not adding the integer's ASCII counterpart. Is there something I'm…
dylanweber
  • 580
  • 7
  • 19
1 2 3
99
100