Summary of the 12th time assignment

Source: Internet
Author: User

    1. String and character pointers

string constant "array", "point"

A sequence of characters enclosed in a pair of double quotes

is seen as a special one-dimensional array of characters that are stored in memory continuously

is essentially a pointer constant pointing to the first character of the string

    1. Char sa[]= "Array";

Char *sp= "point";

Printf ("%s", SA);

Printf ("%s", SP);

Printf ("%s\n" "string");

The value of the array name SA, the pointer sp, and the string "string" are all addresses.

    1. Char sa[]= "This is a string";

Char *sp= "This is a string";

If you want to change the string represented by the array SA, you can only change the contents of the array element.

If you want to change the string that the pointer sp represents, you usually change the pointer's value directly so that she points to the new character.

    1. Common String Handling functions
    2. Function prototypes are given in stdio.h or string.h

Input and output of strings

Input string: scanf () or gets ()

Output string: printf () or puts ()

Stdio.h

    1. SCANF ("%s", str)

Input parameters: Character array name, without address character

Enter the end of a carriage return or a space, and automatically input a string of characters and ' s ' into the array

    1. String copy, concatenate, compare, string length

String copy Strpy (STR1,STR2)

String Connection strcat (STR1,STR2)

string comparison strcmp (STR1,STR2)

String length strlen (str)

String.h

    1. string comparison strcmp (STR1,STR2)

Compare the size of two strings

Rules: by Dictionary (ASCII code order)

If str1 and str2 are equal, return 0

If STR1 is greater than str2, returns a positive integer

Returns a negative integer if str1 is less than str2

Summary of the 12th time assignment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.