C Language Notes Array 2

Source: Internet
Author: User

C99 used to use get and puts to enter the output string, but gets a memory overflow because it is unable to know the size of the memory (for this c99 to get, take the retention posture, C11 directly abolished, but some compilers are still available by default). The get will wait for the end of the input line break, but the string returned by the gets removes the newline character, and the corresponding puts has not added a newline character at the end. Anyway get put class function, always print one line at a time. Fgets and fputs are used to replace the current function, mainly defining the length of this parameter, there is a third parameter stdio and stdout (trouble). Unlike the fgets, the ENTER key is retained, and a '/0 ' is added to the end of the string. The fputs corresponds to no longer add newline characters. The special fputs, when the target memory is full, returns a null pointer, which makes it much more convenient to apply. The corresponding C11 adds two functions for gets_s and s_gets, making the case of strings more complex. Gets_s:1. Can only be used as standard input, do not need to fgets the third parameter 2. Discard newline characters 3. After a memory overflow, first '/0 ' replaces the first character, discarding all subsequent data until a newline character or end of the file appears, returning a null pointer. (What?)  These features also cause the function to fail, even if the user is not aware of the s_gets:1. Replace line breaks with null characters 2. Read part of the data discard other data 3. No longer returns a null pointer. Defective, if the input is missing a newline, the user is completely unaware of what has happened, or do not look good. (C11 got these two things?) SCANF you can understand that a put get object is a string that grabs a character.

16. For String functions

1 Char*strcpy(Char* Restrict S1,Const Char* Restrict S2);//Point pointer to the string at S2 copy to the location pointed to by S12 Char* STRNCPY (Char* Restrict S1,Const Char* Restrict s2,size_t N);//s2 The pointer to the string in the copy to S1 Point3 //Direction position strncpy more than one n refers to having n characters to copy because of a memory overflow problem4 Char* STRCAT (Char* Restrict S1,Const Char* Restrict S2);//string concatenation will s2 stitching to S1, remove null characters, return S1 address5 Char* STRNCAT (Char* Restrict S1,Const Char* Restrict s2,size_t N);//string concatenation will s2 stitching to S1, remove null characters, return S1 address, n characters6 int strcmp(Const Char* S1,Const Char* S2);//If the S1 machine is sorted after S2, returns a positive number, if S1 is sorted before S2, returns a negative number, equal returns 07 //Machine sequencing? Two string The first character A-Z is the actual position in ASCII before and after8 intstrncmpConst Char* S1,Const Char* s2,size_t N);//If S1 machine is sorted after S2, returns a positive number, if S1 is sorted before S2, returns a negative number,9 //Equal return 0 compares n characters and then stops or encounters a null characterTen Char* STRCHR (Const Char* S,intc);//Returns a pointer to the first occurrence of the C character not found returns null One Char* STRPBRK (Const Char(SS,Const Char* S2);//If S1 contains S2 any character, return S1 first address, otherwise null A Char*STRRCHR (Const Char*s,intc);the position of the last occurrence of the//c character, if there is no null - Char*STRSTR (Const Char* S1,Const Char* S2);The first position of the S2 in the//s1 if no null is returned -size_t strlen (Const Char*s);//number of characters not including null characters the 


C language Note Array 2

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.