本文介绍了将字符串转换为全小写字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一系列字符,我想让它们全部更低


int扫描(字符搜索[])

{

char * cPtr;

cPtr = strtok(搜索, - ,。);


while(cPtr!= NULL)

{

//这里我想降低cPtr,如cPtr =

tolower( cPtr)

//但不行

printf("%s",cPtr);

cPtr = strtok( NULL, - ,。;;

}

}


请帮帮我!

很多! :)

Hi everybody,
I have an array of chars that I want to make all lower

int Scan(char Search[])
{
char *cPtr;
cPtr = strtok (Search," -,.");

while (cPtr != NULL)
{
// Here I want to lower cPtr whith somithing like cPtr =
tolower(cPtr)
//but don''t works
printf("%s ", cPtr);
cPtr = strtok (NULL, " -,.");
}
}

Help me please!
Thx a lot! :)

推荐答案



strtok()是一个微妙复杂的函数。只需循环浏览

您使用isalpha()对字母字符进行数组测试,如果

这样,请检查它是否已使用islower()进行小写,如果没有,

转换为tolower()。

strtok() is a subtly complicated function to use. Just loop through
your array testing for an alphabetic character with isalpha() and if
so, check if it''s already in lowercase with islower() and if not,
convert with tolower().





#include< stdio.h>

#include< ctype.h>


int main(void){

int c;


while((c = getchar())!= EOF){

if(isalpha((unsigned char)c)){

if(isupper((unsigned char)c))

c = tolowe r((unsigned char)c);

}

putchar(c);

}

返回0 ;

}

#include <stdio.h>
#include <ctype.h>

int main(void) {
int c;

while((c = getchar()) != EOF) {
if(isalpha((unsigned char) c)) {
if(isupper((unsigned char) c))
c = tolower((unsigned char) c);
}
putchar(c);
}
return 0;
}


这篇关于将字符串转换为全小写字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 14:03