C/String/String Case — различия между версиями
Admin (обсуждение | вклад) м (1 версия: Импорт контента...) |
(нет различий)
|
Текущая версия на 13:22, 25 мая 2010
Change string case using its pointer
<source lang="cpp">
- include <ctype.h>
- include <stdio.h>
int main(void) {
char str[80], *p; printf("Enter a string: "); gets(str); p = str; while( *p ) { *p = toupper(*p); p++; } printf("%s\n", str); /* uppercase string */ p = str; /* reset p */ while( *p ) { *p = tolower(*p); p++; } printf("%s\n", str); /* lowercase string */ return 0;
}
</source>
Convert string to upper case and lower case
<source lang="cpp">
- include <ctype.h>
- include <stdio.h>
int main(void) {
char str[80]; int i; printf("Enter a string: "); gets(str); for( i = 0; str[ i ]; i++) str[ i ] = toupper( str[ i ] ); printf("%s\n", str); /* uppercase string */ for(i = 0; str[ i ]; i++) str[i] = tolower(str[ i ]); printf("%s\n", str); /* lowercase string */ return 0;
}
</source>