String input Problems

Source: Internet
Author: User

String input Problems

String input problems:

 

1. format the input function: scanf (Format String, address );. Match the data entered by the user with the formatted string, assign the matched data to the memory of the address, and use % s as the string format. Note that, when the input character exceeds the length of the array, it overwrites other data in the memory adjacent to the memory occupied by the array. And sometimes the system does not report an error. Assume that an array of 5 char strings is defined. When 12345abc is input, the memory space is simulated as follows:

 

2. Other input string functions:

(1). gets (array name or & variable name) function, get the string you entered and pass it to the array or variable. (I personally don't like it very much .) Using this function in xcode will directly report a warning in the console.

(2) import function: string. h

C language provides a set of library functions in: string. h, which are commonly used:

Strlen (string 1) calculates the length of the string.

Strcpy (string 1, string 2) assigns a value to string 1.

Strcat (string 1 string 2) append string 2 to string 1.

Strcmp (string 1, string 2) compares two strings. If the return value is positive, the former is large. If the return value is negative, the latter is large. If it is zero, the two strings are the same.

 

 

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.