C语言写一函数将字符串大写字母转换成小写字母

如题所述

第1个回答  2009-05-19
void swap(char a[],int n) //n是字符串长度
{
int i;
for(i=0;i<n;i++)
{
if(a[i]>96&&a[i]<123)
a[i]-=32;
}
}
//只写了转换的函数、在主函数中调用就可以了本回答被提问者采纳
第2个回答  2009-05-19
有个函数的

#include <string.h>

char *_strlwr( char *string );

Convert a string to lowercase

Example

/* STRLWR.C: This program uses _strlwr and _strupr to create
* uppercase and lowercase copies of a mixed-case string.
*/

#include <string.h>
#include <stdio.h>

void main( void )
{
char string[100] = "The String to End All Strings!";
char *copy1, *copy2;
copy1 = _strlwr( _strdup( string ) );
copy2 = _strupr( _strdup( string ) );
printf( "Mixed: %s\n", string );
printf( "Lower: %s\n", copy1 );
printf( "Upper: %s\n", copy2 );
}

Output

Mixed: The String to End All Strings!
Lower: the string to end all strings!
Upper: THE STRING TO END ALL STRINGS!
第3个回答  2009-05-19
void ToUpper(char *str)
{
int i;
for (i=0; str[i] != 0; ++i)
{
if ( str[i] >= 'A' && str[i]<= 'Z') str[i] -= 'A'-'a';
}
}
相似回答