zoukankan      html  css  js  c++  java
  • C语言第2

    今个那老哥替我刷题,然后遇到一个打印中文编码得问题,我多嘴一问,为啥 用 unsiged 然后他让我换成char试试;然后出现了以下结果

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
     
     
    #define N 101
     
    int main(int argc, char *argv[]) {
        unsigned char buf[N] = {0};
        printf("请输入一个字符串,长度小于等于100:");
        fgets(buf, N, stdin);
        printf("该字符串的内存编码为:");
        int i = 0;
        for (i = 0; buf[i]; i++) {
            int c = buf[i];
            printf("%x ", c);
        }
        return EXIT_SUCCESS;
    }
    
    
    >>>>>>>>>>>>>>>结果如下
    请输入一个字符串,长度小于等于100:abcABC012中国人
    该字符串的内存编码为:61 62 63 41 42 43 30 31 32 d6 d0 b9 fa c8 cb

    换用 char 结果如下#define N 101

    int main(int argc, char *argv[]) {
         char buf[N] = {0};
        printf("请输入一个字符串,长度小于等于100:");
        fgets(buf, N, stdin);
        int len = strlen(buf);
        if (buf[len - 1] == '
    ') {
            buf[len - 1] = 0;
        }
        printf("该字符串的内存编码为:");
        int i = 0;
        for (i = 0; buf[i]; i++) {
            int c = buf[i];
            printf("%x ", c);
        }
        return EXIT_SUCCESS;
    }
    
    >>>>>>>>>>>>>>
    请输入一个字符串,长度小于等于100:abcABC012中国人
    该字符串的内存编码为:61 62 63 41 42 43 30 31 32 ffffffd6 ffffffd0 ffffffb9 fffffffa ffffffc8

    》》》》》》下两行废话,直接第三行看。

    于是我被补了一下导论课,他如此细腻的一个字节一个字节得讲解了过程,并反复确认我懂了,然后,,,,真刺激,如果没有他,我的c是不是就这样止步不前了。我的数据结构算法分析是不是就不看了

    C语言中函数参数传入动态函数时,自动类型转换为int。此内容在书 137页第四行有说明。

    原文如下“对于没有原型得函数,传递给函数的实参将作缺省参数提升:char short 转换为int float 转换为double类型”。

    
    

  • 相关阅读:
    使用 libevent 和 libev 提高网络应用性能
    An existing connection was forcibly closed by the remote host
    各种浏览器的兼容css
    vs输出窗口,显示build的时间
    sass
    网站设置404错误页
    List of content management systems
    css footer not displaying at the bottom of the page
    强制刷新css
    sp_executesql invalid object name
  • 原文地址:https://www.cnblogs.com/dosu/p/12038011.html
Copyright © 2011-2022 走看看