Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Zitat von »"C/C++ GE-PACKT"«
int toupper(int ch);
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/** * convert a char* to uppercase * */ char* toupper(const char* pcString) { char* pcRet = (char*)malloc(sizeof(char)*strlen(pcString)); // the returnstring int i = 0; // cursor if( !pcRet ) // check if the malloc failed return pcString; // give the original string back, so the program doesn't crash sprintf(pcRet, "%s", pcString); // write the given string in the returnstring // step trougth each char while(pcRet[i]) { pcRet[i] = toupper(pcRet[i]); // convert to uppercase i++; // increment the cursor } return pcRet; // give it back } |
C-/C++-Quelltext |
|
1 |
cout << "toupper(\"tEsT\") = " << toupper("tEsT") << endl; |
Zitat
toupper("tEsT") = TEST
Administrator
Administrator
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 |
const std::string str_to_upper(const std::string& in) { std::string out; out.reserve(in.length()); for(size_t i = 0; i < in.length(); ++i) out.append(toupper(in[i])); return out; } |
C-/C++-Quelltext |
|
1 |
_strupr((char *) String.c_str()); |
Zitat von »"TrikkieMikkie"«
Geht sowas nicht ?
C-/C++-Quelltext
1 _strupr((char *) String.c_str());
Zitat von »"TrikkieMikkie"«
Mmh. Schade, so schön kurz...
Muß ich wohl noch ein wenig nachsitzen und Standards studieren.
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
template< typename T > std::basic_string< T > ToUpper( const std::basic_string< T >& str, std::locale loc = std::locale( "" ) ) { struct helper { typedef std::basic_string< T >::value_type ValueType; helper( const std::locale& loc ) : m_loc( loc ) { } ValueType operator()( ValueType ch ) { return std::toupper( ch, m_loc ); } private: const std::locale& m_loc; } ToUpperFun( loc ); std::string result( str ); std::transform( result.begin(), result.end(), result.begin(), ToUpperFun ); return result; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
void ToUpper( char* str ) { char* p = str; while ( *p ) { *p = ::toupper( *p ); ++p; } } int main() { char buffer[ 256 ]; strcpy( buffer, "Hallo Welt" ); ToUpper( buffer ); printf( "%s\n", buffer ); std::cin.get(); } |
C-/C++-Quelltext |
|
1 2 |
char* foo = "Hallo Welt"; // Ist eigentlich const char* foo = ... ToUpper( foo ); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <iostream> #include <cctype> inline char funky_conversion(char c) { return c ^ 42; } template<typename T, typename Function> inline T transform(T str, Function op) { for (T s = str; *s; *s = op(*s), ++s); return str; } int main() { char blub[] = "test"; std::cout << transform(blub, toupper) << std::endl; std::cout << transform(blub, funky_conversion); return 0; } |
C-/C++-Quelltext |
|
1 |
std::transform( buffer, buffer+10, buffer, ::toupper ); |
Werbeanzeige