Questions tagged [toupper]

In C / C++ toupper function converts a given character to uppercase according to the character conversion rules defined by the currently installed C locale. In the default "C" locale, the following lowercase letters abcdefghijklmnopqrstuvwxyz are replaced with respective uppercase letters ABCDEFGHIJKLMNOPQRSTUVWXYZ.

176 questions
160
votes
2 answers

Why is the alphabet split into multiple ranges in this C code?

In a custom library I saw an implementation: inline int is_upper_alpha(char chValue) { if (((chValue >= 'A') && (chValue <= 'I')) || ((chValue >= 'J') && (chValue <= 'R')) || ((chValue >= 'S') && (chValue <= 'Z'))) return…
Vladimir Ch.
  • 1,004
  • 1
  • 8
  • 16
35
votes
5 answers

Do I need to cast to unsigned char before calling toupper(), tolower(), et al.?

A while ago, someone with high reputation here on Stack Overflow wrote in a comment that it is necessary to cast a char-argument to unsigned char before calling std::toupper and std::tolower (and similar functions). On the other hand, Bjarne…
Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
34
votes
5 answers

Why can't "transform(s.begin(),s.end(),s.begin(),tolower)" be complied successfully?

Given the code: #include #include #include #include using namespace std; int main() { string s("ABCDEFGHIJKL"); transform(s.begin(),s.end(),s.begin(),tolower); cout<
liu
  • 937
  • 1
  • 9
  • 15
23
votes
3 answers

Why putchar, toupper, tolower, etc. take a int instead of a char?

In C, strings are arrays of char (char *) and characters are usually stored in char. I noticed that some functions from the libC are taking as argument integers instead of a char. For instance, let's take the functions toupper() and tolower() that…
Maxime Chéramy
  • 17,761
  • 8
  • 54
  • 75
12
votes
4 answers

Capitalizing letters. R equivalent of excel "PROPER" function

Colleagues, I'm looking at a data frame resembling the extract below: Month Provider Items January CofCom 25 july CofCom 331 march vobix 12 May vobix 0 I would like to capitalise first letter of each word and lower the…
Konrad
  • 17,740
  • 16
  • 106
  • 167
11
votes
1 answer

ToUpperInvariant() – is MSDN wrong on its recommendation?

In Best Practices for Using Strings in the .NET Framework, StringComparison OrdinalIgnoreCase is recommended for case-insensitive file paths. (Let's call it Statement A.) I can agree with that, because I can create two files in the same…
miroxlav
  • 11,796
  • 5
  • 58
  • 99
10
votes
6 answers

Changing a lowercase character to uppercase in c++

Here is the code that i wrote. When i enter a lowercase character such as 'a', it gives me a blank character but afterwards it works well. Can you tell me what i did wrong? Thanks. :) #include #include using namespace std; int…
Manisha Singh Sanoo
  • 919
  • 1
  • 13
  • 42
6
votes
1 answer

f# System.Char.ToUpper

I have an exercise that asks for a function that converts all characters of a string to uppercase using System.Char.ToUpper So first I changed the string to a char array and changed the array into a list of chars let x =…
jynx678
  • 249
  • 4
  • 13
6
votes
3 answers

Converting Char to Uppercase From User Inputted Data

I am trying to create a program for a hotel where the user is to enter a character (either S, D, or L) and that is supposed to correspond with a code further down the line. I need help converting the user input (no matter what way they enter it) to…
user3418316
  • 69
  • 1
  • 1
  • 2
6
votes
4 answers

Is it more common/standard to compare uppercase or lowercase?

I'm in my first six months of programming on the job and I'm still getting a feeling for standards and best practices. When performing string or char comparison, is it more common to use ToUpper to compare uppercase characters or ToLower for…
FLGMwt
  • 706
  • 4
  • 18
5
votes
2 answers

Transforming a string_view in-place

std::transform, as of C++20, is declared constexpr. I have a bunch of string utility functions that take std::string arguments, but a lot of the usage ends up just passing in small, short, character literal sequences at compile-time. I thought I…
Casey
  • 10,297
  • 11
  • 59
  • 88
5
votes
1 answer

Haskell-ghci, function toUpper not found?

I'have right now installed the ghci version 8.6.2 and following a tutorial I write: toUpper "something" but ghci compiler prints out: Variable not in scope: toUpper :: [Char] -> t Do I miss some libraries or anything else?
glc78
  • 439
  • 1
  • 8
  • 20
5
votes
3 answers

How can I assign a new char into a string in Go?

I'm trying to alter an existing string in Go but I keep getting this error "cannot assign to new_str[i]" package main import "fmt" func ToUpper(str string) string { new_str := str for i:=0; i='a' &&…
user3765713
  • 133
  • 2
  • 13
5
votes
3 answers

How to set a string to all lowercase

I have a char foo[SIZE]; //(string) and have inputed it correctly using %s (as in it printfs the correct input), but now want to set it to lowercase. So I tried using if (isupper(*foo)) *foo=tolower(*foo); ie when I do: printf("%s" foo);…
user2450044
  • 59
  • 1
  • 1
  • 3
4
votes
2 answers

Unsure as to why toupper() is cutting off last letter in C

So the goal of this program is to basically take a 26 letter 'key' in the terminal (through argv[]) and use its index's as a substitution guideline. So there are 2 inputs you enter in the terminal, one in the argv[] and one is just a plain…
Soccerball123
  • 741
  • 5
  • 17
1
2 3
11 12