Standard C programming notes day07 common standard library introduction, string input processing, character pointer usage

Source: Internet
Author: User
Common standard libraries:
Assert. h: assert macro. Can perform self-check
Ctype. h: character processing, character classification, and size conversion
Errno. h: handle error messages
Float. h: Floating Point
Limits. h: the integer size, which provides a macro that describes the integer type.
Lcale. h: localization
Math. h: mathematical functions
Setjmp. h: Jump
Signal. h: Signal Processing
Stdarg. h: Variable Length Parameter Processing
Stddef. h: Definition of frequently used types
Stdio. h: Input and Output
String. h: string processing
Stdlib. h: other functions, strings, numbers, random numbers, memory management, system communication, search sorting, etc.
Time. h: processing time and date
Stdbool. h: boolean type and value




Conversion between pointer and value:
Void (P = NULL;
Int num = 8;
P = & num;
Int A = * (int *) P );


In the computer, the address of the first character of the string is used to represent the entire string (char *).
Multiple identical strings are the same (Address) at runtime ).
Multiple strings can be written together directly without strcat connection, for example, char * pstr = "123" "456 ";
Only character arrays containing '\ 0' can be used as strings.
Char STR [] = "ABCDE"; // contains 6 characters, the last character is '\ 0', And the ascll code is 0.
String function: strlen/strcat/strcmp/strncmp/strcpy/strncpy


Input string processing to automatically remove unnecessary input:
Char s [50] = {0 };
Fgets (s, 50, stdin );
If (strlen (S) = 49 & S [48]! = '\ N' & S [49] =' \ 0 ')
{
Scanf ("% * [^ \ n]"); scanf ("% * C ");
}
Fgets (): The length is (string digits-1). The character is: (when there are few characters) content + "\ n \ 0" Or: (when there are many characters) content + "\ 0 ".
Pointer operation string:
Char * STR [50] = "10 \ 020 \ 030 \ 040 \ 050 \ 0 ";
Char * pstr [5] = {0 };
Pstr [0] = STR;
Pstr [1] = STR + 3;
Pstr [2] = STR + 6;
Pstr [3] = STR + 9;
Pstr [4] = STR + 12;
Char c = * (pstr [0]); // The value of C is '1'

Printf ("% s", pstr [0]); // output: 10



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.