Increment the first byte of a string by one

后端 未结 3 1747
庸人自扰
庸人自扰 2021-01-26 06:16

I\'ve got a main program:

int main() {
    char *str = \"hello\";
    printf(\"%s\\n\", str);
    /* Shift first byte 1 to get \"iello\" */

    /*          


        
3条回答
  •  一生所求
    2021-01-26 07:10

    Do something like:

    #include 
    #include 
    
    int main() {
    char str[] = "hello";
    printf("%s\n", str);
    
    //str[0]=str[0]+1;
    
    // to get uppercase letter include ctype.h header
    
    str[0] = toupper(str[0] + 1);
    
    printf("%s\n", str);
    return 0;
    }
    

提交回复
热议问题