Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;:如何在不使用ctype函数的情况下将小写转换为大写和小写? intmain(){ 字符文本[500]; int j,h,op; 字符b[]=“abcdefghijklmnopqrstuvwxyz”; 字符a[]=“ABCDEFGHIJKLMNOPQRSTUVWXYZ”; cout_C++_String_Ctype - Fatal编程技术网

C++ C++;:如何在不使用ctype函数的情况下将小写转换为大写和小写? intmain(){ 字符文本[500]; int j,h,op; 字符b[]=“abcdefghijklmnopqrstuvwxyz”; 字符a[]=“ABCDEFGHIJKLMNOPQRSTUVWXYZ”; cout

C++ C++;:如何在不使用ctype函数的情况下将小写转换为大写和小写? intmain(){ 字符文本[500]; int j,h,op; 字符b[]=“abcdefghijklmnopqrstuvwxyz”; 字符a[]=“ABCDEFGHIJKLMNOPQRSTUVWXYZ”; cout,c++,string,ctype,C++,String,Ctype,如果您不希望此代码依赖于ASCII表的值(尽管这会使您的生活更轻松),那么遵循您有趣的代码的精神,可以实现将字母转换为小写的函数: int main(){ char text[500]; int j,h,op; char b[]=" abcdefghijklmnopqrstuvwxyz"; char a[]=" ABCDEFGHIJKLMNOPQRSTUVWXYZ"; cout<<"insert text:";fflush(stdin);gets(texto);

如果您不希望此代码依赖于ASCII表的值(尽管这会使您的生活更轻松),那么遵循您有趣的代码的精神,可以实现将字母转换为小写的函数:

int main(){
char text[500];
int j,h,op;
char b[]=" abcdefghijklmnopqrstuvwxyz";
char a[]=" ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
cout<<"insert text:";fflush(stdin);gets(texto); 
        system("cls");
            cout<<"1-Minus to Mayus"<<endl;
            cout<<"2-Mayus to Minus"<<endl;
        cin>>op;
    system("cls");
    if (op==1)
                    {
                                j=0;
                                h=0;
                                while(j<28){

                                    if(text[h]==b[j]){
                                        text[h]=a[j];
                                        h++;
                                        j=0;
                                    }
                                    j++;
                                }
                                cout<<text<<endl;
                                system("pause");
                    }
                    else if (op==2)
                    {
                                j=0; 
                                h=0;
                                while(j<28){

                                    if(text[h]==a[j]){
                                        text[h]=b[j];
                                        h++;
                                        j=0;
                                    }
                                    j++;        
                                }
                                cout<<text<<endl;
                                system("pause");
                }
            }
const char小写[]=“abcdefghijklmnopqrstuvwxyz”;
const char CAPITALS[]=“ABCDEFGHIJKLMNOPQRSTUVWXYZ”;
void toLowerCase(字符串和s){
for(无符号整数i=0;i
试试这个

const char LOWERCASES[] = " abcdefghijklmnopqrstuvwxyz";
const char CAPITALS[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";

void toLowerCase(string &s) {
    for (unsigned int i = 0; i < s.size(); ++i) {
        for (unsigned int l = 0; l < 27; ++i) {
            if (s[i] == CAPITALS[l]) {
                s[i] = LOWERCASES[i];
                break;
            }
        }
    }       
}
intmain(){
int-ss,T;
字符文本[100];

您的代码看起来过于复杂,无法完成这项简单的任务。请看一下在“编程入门101”中,他们是如何教授ASCII的还有吗?@user0042——问题陈述不限于ASCII,所以这可能不是一个选项。我真诚地怀疑。我打赌100个四分之一的问题集是ASCII。首先要做的是实际编写一个“从低到高的函数”不是将所有代码塞进
main
。是的,这将使用编译器通过
-execution charset
aka
-fexec charset
输出的内容,而不是ASCII。什么是
tam()
int main(){

int ss,T;

char text[100]; 

cout<<"Insert text ";gets(text);
T=tam(texto);
    cout<<"1)Menu "<<endl;
    cout<<"2)Upercase "<<endl;
    cout<<"3)LowerCase "<<endl;
    cout<<"4)Random"<<endl;cin>>ss;

switch(ss){

    case 2:
            for(int i=0 ; i<T ; i++){
                if(text[i]>=97 && text[i]<=122)
                    text[i]=int(text[i])-32;
            }
            cout<<text<<endl;

    break;  

    case 3:
            for(int i=0 ; i<T ; i++){
                if(text[i]>=65 && text[i]<=90)
                    text[i]=int(text[i])+32;
            }
            cout<<text<<endl;

    break;


    case 4:
            for(int i=0 ; i<T ; i++){
                if(text[i]>=97 && text[i]<=122)
                    text[i]=int(text[i])-32;
                else
                    text[i]=int(text[i])+32;    
            }

            cout<<text<<endl;

    break;
}