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.

char
Filter by
Sorted by
Tagged with
2 votes
2 answers
70 views

How to compare two strings in C with the number of characters compared being the number of characters in a string received from a file

I am trying to create a "bank" program in C which has unique logins and to do so, I have a file of usernames and check if the username entered by the user matches a pre-existing one and have ...
2 votes
2 answers
70 views

How can I implement a linear time implementation of a function that counts the number of occurrences of a non-consecutive subsequence?

My Programming I class assigned an exercise in which we have to implement a function that counts the number of occurrences of a non-consecutive subsequence in a string. This is what we're asked to do: ...
945 votes
14 answers
1.3m views

How to convert a char to a String?

I have a char and I need a String. How do I convert from one to the other?
16 votes
5 answers
7k views

Why is it possible to assign a const char* to a char*?

I know that for example "hello" is of type const char*. So my questions are: How can we assign a literal string like "hello" to a non-const char* like this: char* s = "hello"; // "hello" is type of ...
-2 votes
2 answers
122 views

C++ redefinition in while loop

I'm trying to make a loop that asks coordinates from the user, and then prints those coordinates if they are in range of [1, 3]. If they are out of range, it prints error message. If input is 'q' it ...
0 votes
1 answer
81 views

Cast Int as Char * and Back in C

Edit: I've edited my question to fix some mistakes and make what I want to do clearer. I want to convert a 4 byte integer into a char * of length exactly 4 bytes and then back to an int. I understand ...
3 votes
4 answers
4k views

Both null and empty char are equal in java

I have doubt while taking a null or empty char check in Java. Is both have to be checked in any way. For example in database the variable length for Char is 1 . It will allow null as well. So if you ...
4 votes
3 answers
16k views

Return character from ASCII code in Windows Batch

I made a program for coding text strings in Batch. Now, I have to convert the ASCII code to a character. In reality, I have to do the opposite. I divided the chars of the strings and I want to ...
0 votes
2 answers
90 views

Sort string with lowercase first in case of same alphabet type

How to sort a std::string with lowercase first in case of same alphabet type? #include <iostream> #include <string> #include <algorithm> int main() { std:...
1 vote
4 answers
31k views

convert unicode to char

How can I convert a Unicode string to a char* or char* const in embarcadero c++ ?
0 votes
1 answer
61 views

How to advance row-major and wrap around rows in a Java 2D array?

For a small Java application, I have a constant SIZE x SIZE 2D char array called FIELD that I am trying to move two objects (represented by char symbols) through. I have two methods in my Field class ...
0 votes
1 answer
151 views

Why does the validation for lowercase letters always fail?

I am writing a program that takes a password as input and validates based on the following criteria: 8 characters or more at least one uppercase letter at least one lowercase letter at least one ...
2 votes
6 answers
20k views

How to convert a byte to a char, e.g. 1 -> '1'?

How to convert a byte to a char? I don't mean an ASCII representation. I have a variable of type byte and want it as a character. I want just following conversions from byte to char: 0 ->'0' 1 ->'1' ...
3 votes
2 answers
494 views

What is the difference between C# Runes and the char data type?

What is the difference between Runes and the char data type in C# when it comes to handling Unicode characters?How does using Runes impact the processing and manipulation of non-ASCII characters? Can ...
-3 votes
1 answer
96 views

Is there any function that can count with char value? [closed]

Write a program to accept a sentence and perform the following tasks: Count number of vowels and consonants present in each word Generate the output of the frequency in form of a bar graph, where V ...
43 votes
5 answers
29k views

Why is char distinct from signed char and unsigned char?

Consider the following code: #include <iostream> #include <type_traits> int main() { std::cout << "std::is_same<int, int>::value = " << std::is_same<...
0 votes
1 answer
52 views

What is the data type of characters ie. "!", "+" in FreeBASIC?

I tried char and vargchar, but none of them work. i want to build a calculator and want to ask the user what symbol they want to use like +,- i tried doing char and vargchar, but none of them work. ...
0 votes
2 answers
121 views

How can I wprintf a value of a character in C++

How can I print the Ascii value of one char (wstring) ? For example I want to get the Ascii Value of Ö which is 214. I tried this: std::wstring ws2 = L"Ö"; wprintf(L"This is ...
0 votes
0 answers
42 views

Difference in output of program in c for scanning character value due to space .(In Dev c++)

Problem: space role in nested switch Even if i is char, why does code work? After making i an int min file is formed i.e. no output. Here my program goes: #include <stdio.h> int main() { ...
2 votes
2 answers
77 views

Why does my reader output square symbols?

I am following some tutorial vids and learning how to read files with java. In this example the instructor creates a char array sized to 100 and then uses the FileReader class to read a text file and ...
2 votes
6 answers
164 views

Weird output printing arrays in C

I decided to do the CS50 course again and tried to go about solving some of the problems differently. There is a task where you have to print pyramids with two spaces between each half using the '#' ...
0 votes
1 answer
104 views

Inputting Multibyte Characters in C

I'm currently working on a program in C and I need to read a multibyte character from the keyboard. I want to input a two-byte character (e.g., "ą") and ensure that I can't input more than ...
0 votes
1 answer
44 views

How to use a string as code to initialize another string in C#?

I have a long list of strings such as: "njro\x68qgbx"\xe4af\"\\suan" As you all know, those could be understood as a string initializing code-command such as: string com = "...
0 votes
1 answer
90 views

Postgres - CHAR isn't blank-padded?

According to the Postgres documentation:https://www.postgresql.org/docs/current/datatype-character.html CHAR data type is blank-padded to the required size. I don't understand why the second query ...
0 votes
0 answers
26 views

error Illegal char <:> at index 42: com.em.app-mergeDebugResources-60:/values/values.xml, when implementation 'com.cometchat:chat-uikit-android:4.0.4'

Caused by: com.android.aaptcompiler.ResourceCompilationException: Failed to compile values resource issue whenever building app Caused by: com.android.aaptcompiler.ResourceCompilationException: Failed ...
-1 votes
3 answers
50 views

How to ask a question repeatedly until I get the right answer as a character

I should ask "choose" and the user should type a b or c if he types somehting else, it should repeat the question. I don't even understand how I do that and then I have another problem: ...
36 votes
11 answers
128k views

Incrementing Char Type In Java

While practicing Java I randomly came up with this: class test { public static void main(String arg[]) { char x='A'; x=x+1; System.out.println(x); } } I thought ...
0 votes
1 answer
103 views

How to get C input that accepts a float or a character as a value

As i said, i need to be able to accept the characters a b c d e as an input but it also needs to be able to accept any floating point numbers. i’m not sure if this is even possible but if someone ...
39 votes
5 answers
187k views

Error "cannot convert 'std::basic_string<char>' to 'const char*' for argument '1' to 'int system(const char*)'"

I get this error: "invalid operands of types 'const char*' and 'const char [6]' to binary 'operator+'" when I try to compile my script. Here should be the error: string name = "john&...
0 votes
2 answers
80 views

How to count how many and what kind of digits are found in a string and replace all letters with spaces?

I need to solve this task using library string functions and without them. I solved without special functions: void without_functions(string str) { int* how_many_num = new int[10]; for (int i =...
0 votes
1 answer
61 views

Is there a standard for disambiguation in character sets?

Is there any form of standard for a character set where similar-looking characters are excluded? Examples of characters that can easily be misread by a human: il1! oO0 4AH 5S 7T I'm asking because I'...
-2 votes
2 answers
150 views

I'm trying to make a wordle clone in java but duplicate letters wont display in the right color (display in yellow when they should display in red) [duplicate]

do { userInput = input.nextLine().toUpperCase(); // Convert input to uppercase to match secretWord's case if (userInput.length() > 5) { System.out.println("Invalid Guess, word ...
-1 votes
1 answer
47 views

Arduino Mhz 433 send a long

I am working on a project where I am sending data via the Arduino Mhz 433 transmitter and receiver. The data code is coming from a FSR. How ever the code for the data I am receiving is in a Long and ...
-1 votes
3 answers
171 views

How to count only a period in C?

I need to count only the periods (.) from a string. To do that, I'm using the ispunct function from the ctype.h library. I don't want to count the comas (,) and neither the exclamation marks (!). How ...
2 votes
2 answers
176 views

Fibonacci for letters

I was programming a code for a case provided by my university. It was about making a Fibonacci function, but for letters. For example, if f(0) -> a, f(1) -> b, then f(2) -> ba, and so on. I ...
1 vote
3 answers
127 views

Find common words between two strings

How do I compare and find common words between two tokenized word strings? Please help me find a new solution. #include <stdio.h> #include <string.h> #include <ctype.h> #define MAX ...
11 votes
1 answer
17k views

How does MySQL varchar know how many bytes indicate the length?

The MySQL manual and several StackOverflow answers make it clear that varchar uses: 1 byte for varchars with 0-255 characters in them 2 bytes for varchars with more than 255 characters in them. The ...
0 votes
1 answer
106 views

How to check if input is char or not

I am learning c and are making a "guess the number" game. I am getting the player to enter a name and i want to check if it's characters only. I want to makes this very simple game a little ...
72 votes
8 answers
152k views

In Java, how to find if first character in a string is upper case without regex

In Java, find if the first character in a string is upper case without using regular expressions.
0 votes
1 answer
63 views

Assigning an Integer literal to a char data type in Java [duplicate]

While learning Java, I came across the statement - "You cannot assign an integer to a char data type directly without explicitly casting it" I tried the below example : char ch = 65; System....
1 vote
1 answer
66 views

why am getting strange output "÷" when performing the simple follwoing c++ lines [duplicate]

When running this code: #include <iostream> using namespace std; int main() { // Signed char signed char signedCharValue = -10; cout << "Signed char: " << ...
33 votes
13 answers
65k views

Putting char into a java string for each N characters

I have a java string, which has a variable length. I need to put the piece "<br>" into the string, say each 10 characters. For example this is my string: `this is my string which I need to ...
0 votes
0 answers
47 views

Program to read a file and generate a random number

Let me explain the problem first. The below shows the generation of a random number from a text file having a book. * **Seed Initialization**: The PRNG (Pseudorandom Number Generator) is initialized ...
0 votes
0 answers
29 views

Weird behavior when accessing string array in C [duplicate]

I have started learning C right now and I'm currently solving some random online exercises, and found a behavior right now, which I don't seem to understand. The exercise says: print the numbers of 1 ...
0 votes
1 answer
32 views

Charset Conversion € \x80

I'm sure I'm missing something obvious here but I have a string that at a certain point has the € and I know that this means the next section repeats 128 times or if the character is 7 then it repeats ...
-1 votes
1 answer
8k views

How to convert a double into a char* [duplicate]

I am heavily struggling with a question which should be very easy: how do I do a simple type conversion (from double into char*) in basic C. I have found quite some solutions, but they are all based ...
2 votes
6 answers
3k views

Calculate the frequency of characters in a string (Java, Performance)

Problem I wrote this program to check the number of times that each letter appears in a string input by the user. It works fine, but is there a more efficient or alternative solutions of going about ...
-2 votes
2 answers
107 views

I'm having a problem with pop_back() in c++

I'm trying to write a program in C++ that can swap the vocals on a sentence (by reversing it). #include <iostream> #include <string> #include <vector> int main() { // declare ...
0 votes
3 answers
120 views

What is a good way of initializing a vector of char* from string literals?

Until C++11, one was able to write the following: #include <vector> using namespace std; int main_under_test(int argc, char* argv[]) { return 0; } int main() { vector<char*> args ...
0 votes
0 answers
53 views

Program not producing correct output, however code is reviewed [duplicate]

I am writing a C program that keeps track of the total cost of items in a shopping cart. Input must be taken in float for the price and then for each input, another input to ask to continue is to be ...