C language displays content on the screen

巴扎黑
Release: 2017-09-06 10:56:00
Original
3601 people have browsed it
We have two ways to obtain information from the computer: one is to look at the text, pictures, videos, etc. on the screen, and the other is to listen to the sound from the speaker.

It’s still a bit troublesome to make the speaker make sound. Let’s first take a look at how to display some text on the screen. For example, to display "php Chinese website" on the screen:
puts("php中文网");
Copy after login
Here is an unfamiliar vocabulary puts, which is used to let the computer display text on the screen.

A more professional name:
  • "Displaying text on the screen" is called Output;

  • Each text is a character (Character) ;

  • The combination of multiple characters is a character sequence, called string (String) .


puts is the abbreviation of output string, which means "output string".

In C language, the string needs to be surrounded by double quotes" "surrounded, php中文网is nothing, the computer does not recognize it," PHP Chinese website " is the string.

puts When outputting a string, the string needs to be placed within ( ).

In Chinese and English, use respectively. and . represent the end of a sentence, while in C language, use ; to represent the end of a statement. puts("php中文网") expresses the complete meaning and is a complete statement. You need to add ; at the end to indicate that the current statement is over.

To sum up, the above statement can be divided into three parts:
  • puts( ) Commands the computer to output a string;

  • "C Language Chinese Network" is the content to be output;

  • ; indicates the end of the statement.

Selection of input method

puts("php中文网");The brackets, double quotes, and semicolons in are all English symbols, and they are Half-width, so you need to switch to the English half-width input method when writing code, as shown in the following figure:

Figure 1: Sogou input method

The C language originated from In the United States, words, punctuation, and special symbols must use the English half-width input method to be effective, otherwise they will not be recognized. Readers should pay attention to distinguishing between Chinese and English punctuation.

Similar punctuation marks in Chinese and English are:
  • Chinese semicolon; and English semicolon;;

  • Chinese commas , and English commas ,;

  • Chinese colon : and English colon :

  • Chinese brackets () and English brackets ();

  • Chinese question mark? and English question mark ?;

  • Chinese single quotation mark '' and English single quotation mark ' ';

  • Chinese double quotation marks " " and English double quotation marks " ".

The difference between full-width and half-width input methods

The difference between full-width and half-width input methods mainly lies in other characters besides Chinese characters, such as punctuation marks, English letters, Arabic numerals, etc. Full-width characters and Half-width characters occupy different sizes of space.

On a computer screen, a Chinese character occupies the space of two English characters. People call the space occupied by an English character "half-width", while the space occupied by a Chinese character is called "full-width". ".

Punctuation marks, English letters, Arabic numerals and other characters are different from Chinese characters. They are treated as English characters in half-width state, and as Chinese characters in full-width state. Please see the example below.

Half-width input:

C language Chinese website! Hello C,I like!

Full-width input:

C language Chinese website! Hello C,I like!

The other most important point is: the Unicode encoding corresponding to the "same" character is different in the full-width and half-width states.


Picture: Sogou input method half-width and full-width

我们知道,在编程时要使用英文半角输入法。为了加强练习,出个选择题,请大家判断下面哪一种描述是正确的:
A) 编程的时候不用在意中英文符号的区别
B) 在源代码的任何地方都不能出现中文汉字、字符等
C) 感叹号没有中文和英文的区别
D) 编程时,使用的英文引号,也有左引号和右引号的区别
E) 中文和英文模式下的制表符(键盘tab键)输入效果一致

答:E 选项正确。

C语言程序的整体框架

puts 可以在显示器上输出内容,但是仅有 puts 是不够的,程序不能运行,还需要添加其他代码,构成一个完整的框架。完整的程序如下:
#include 
int main()
{
    puts("php中文网");
    return 0;
}
Copy after login
第 1~3 行、第 5~6 行是固定的,所有C语言源代码都必须有这几行。你暂时不需要理解它们是什么意思,反正有这个就是了,以后会慢慢讲解。

但是请记住,今后我们写的所有类似 puts 这样的语句,都必须放在{ }之间才有效。

上面的代码,看起来枯燥无趣,不好区分各个语句,我们不妨来给它们加上颜色和行号,如下所示:
#include int main(){    puts("php中文网");    return 0;}
Copy after login
Copy after login

颜色和行号是笔者自己加上去的,主要是为了让大家阅读方便,明显地区分各个语句,C语言本身没有对这些作要求,你可以随意设置各个字符的颜色,也可以没有颜色。

The above is the detailed content of C language displays content on the screen. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!