toupper

toupper returns integer rather than char

陌路散爱 提交于 2019-11-30 09:06:06
问题 for the following function void display() { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (board[i][j] < 84 && (i+j)%2 == 0) SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 0x70); else if (board[i][j] < 84 && (i+j)%2 == 1) SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 0xc0); else if (board[i][j] > 97 && (i+j)%2 == 0) SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 0x7c); else if (board[i][j] > 97 && (i+j)%2 == 1) SetConsoleTextAttribute(

C function to capitalize first letter of words in an array

跟風遠走 提交于 2019-11-29 16:00:14
I'm pretty new to C and am hitting a wall when creating the below function. I want to use this function to make the first letter of a word upper case for a static character array (char string[]. It looks ok to my eye, but I'm getting some syntax errors which are probably pretty basic. compiler errors: error: invalid conversion from const char' to const char*' initializing argument 1 of `size_t strlen(const char*)' assignment of read-only location void Cap(char string[]){ int i; int x = strlen(string); for (i=1;i<x;i++){ if (isalpha(string[i]) && string[i-1] == ' '){ // only first letters of a

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

自古美人都是妖i 提交于 2019-11-28 10:51:58
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 both use int . The man page says: If c is not an unsigned char value, or EOF, the behavior of these functions is undefined. My guess is that with a int , toupper and tolower are able to deal with unsigned char and EOF . But in fact EOF is in practice (is there any rule about its value?) a value that can be stored with a char , and since those

C function to capitalize first letter of words in an array

℡╲_俬逩灬. 提交于 2019-11-28 10:03:55
问题 I'm pretty new to C and am hitting a wall when creating the below function. I want to use this function to make the first letter of a word upper case for a static character array (char string[]. It looks ok to my eye, but I'm getting some syntax errors which are probably pretty basic. compiler errors: error: invalid conversion from const char' to const char*' initializing argument 1 of `size_t strlen(const char*)' assignment of read-only location void Cap(char string[]){ int i; int x = strlen

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

十年热恋 提交于 2019-11-27 03:51:45
问题 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 both use int . The man page says: If c is not an unsigned char value, or EOF, the behavior of these functions is undefined. My guess is that with a int , toupper and tolower are able to deal with unsigned char and EOF . But in fact EOF is in

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

百般思念 提交于 2019-11-27 00:52:43
Given the code: #include <iostream> #include <cctype> #include <string> #include <algorithm> using namespace std; int main() { string s("ABCDEFGHIJKL"); transform(s.begin(),s.end(),s.begin(),tolower); cout<<s<<endl; } I get the error: No matching function for call to transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator

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

最后都变了- 提交于 2019-11-25 23:42:23
问题 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 Stroustrup does not mention the need to do so in the C++ Programming Language . He just uses toupper like string name = \"Niels Stroustrup\"; void m3() { string s = name.substr(6,10); // s = \"Stroustr up\" name.replace(0,5,\"nicholas\"); // name becomes