• C程序语言行数统计


    原文
    The next program counts input lines. As we mentioned above, the standard library ensures
    that an input text stream appears as a sequence of lines, each terminated by a newline. Hence,
    counting lines is just counting newlines:

    #include <stdio.h>
    /* count lines in input */
      
    main()
      {
          int c, nl;
            nl = 0;
          while ((c = getchar()) != EOF)
            if (c == '\n')
              ++nl;
          printf("%d\n", nl);
      }
    

    The body of the while now consists of an if , which in turn controls the increment ++nl . The
    if statement tests the parenthesized condition, and if the condition is true, executes the
    statement (or group of statements in braces) that follows. We have again indented to show
    what is controlled by what.

    The double equals sign == is the C notation for ``is equal to'' (like Pascal's single = or
    Fortran's .EQ. ). This symbol is used to distinguish the equality test from the single = that C
    uses for assignment. A word of caution: newcomers to C occasionally write = when they
    mean == . As we will see in Chapter 2, the result is usually a legal expression, so you will get
    no warning.


    中文翻译:

    下一个程序统计输入的行数,接上文所说,标准库确保输入文本流以有顺序的行的形式出现,每行以换行符结尾。因此,计算行数就是计算换行数。

    代码
    

    while的主体由if构成,然后控制增量++nl.if语句测试带括号的条件,如果条件是真,就执行随后的语句(或者大括号里的语句)。我们再次使用缩进符,是为了展示哪个语句是是由哪个语句控制的。
    双等于符号在c语言的意思是 "是否等于" (例如Pascal语言的"="符号或者Fortran语言的 "EQ").这个相等检验符号区分于c语言中的表示赋值的单等于符号 "=",提醒一句,新手偶尔会用 “=”来表示“==”。我们将在第二章中看到,结果通常是一个合法的表达式,所以你不会得到任何警告。


    原文:
    A character written between single quotes represents an integer value equal to the numerical
    value of the character in the machine's character set. This is called a character constant,
    although it is just another way to write a small integer. So, for example, 'A' is a character
    constant; in the ASCII character set its value is 65, the internal representation of the character
    A . Of course, 'A' is to be preferred over 65 : its meaning is obvious, and it is independent of a
    particular character set.

    中文翻译:
    一个单引号之间的字符等于这个字符在机器字符集中的对应的整型数值。这叫做字符常量。尽管这只是小整数的另一种写法,所以,举个例子 ,'A' 是字符常量.在ASCII字符串集里它的内部表示为65,当然,
    A比65的表现方式更直白,他独立于特定的字符串集。

    讲解:
    举例子

    #include <stdio.h>
    void main()
    {
            char a;
            char b;
    
            a=65;
            b='A';
            printf("%c", a);
            printf("%c", b);
    }
    

    结果 AA;

    #include <stdio.h>
    void main()
    {
            int a;
            int b;
    
            a='A';
            b=65;
    
            printf("%d", a);
            printf("%d", b);
    }
    

    结果 6565;

    相信大家都明白了吧。

  • 相关阅读:
    可能有点用的东西
    专题整理
    模拟赛x+1
    【原】如何利用 events 提升 k8s 集群可观察性
    【原】k8s ingress-nginx 针对指定 User-Agent 爬虫进行限速
    装饰者模式-动态的包装原有对象的行为
    观察者模式-将消息通知给观察者
    策略模式-定义一个算法族
    工厂模式-将对象的创建封装起来
    单例模式的五种实现方式及优缺点
  • 原文地址:https://www.cnblogs.com/xuyaoxiang1991/p/15880369.html
Copyright © 2020-2023  润新知