The use of memset,strcpy, sprintf and other functions in C language

Source: Internet
Author: User
Tags sprintf

The following knowledge points are scattered, often used in programming, make a note:

1,memset

Function prototype: void * memset (void * Dst, int Val, size_t size);

Function: Sets the value of the first size byte of the DST that has opened up the memory space to a value of Val

Such as:

memset (Header->wsa__messageid, 0, 100); Empty the contents of Header->wsa__messageid

2,strcpy

Function prototypes: extern char *strcpy (char *dest,char *src);

Function: Copies a null-terminated string referred to by SRC to the string referred to by Dest.

Such as:

strncpy (Header->wsa__messageid, _hwid, strlen (_hwid)); Copy the contents of the string _hwid into the Header->wsa__messageid string

3,sprintf

Function: String Formatting command

Such as:

sprintf (_hwid, "urn:uuid:%ud68a-1dd2-11b2-a105-%02x%02x%02x%02x%02x%02x",
Flagrand, Macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]); Flagrand, Macaddr[0]~macaddr[5] Write//to string "Urn:uuid:%ud68a-1 Dd2-11b2-a105-%02x%02x%02x%02x%02x%02x ", and save it to _hwid inside

4,sscanf

Such as:

SSCANF (str, "%d.%d.%d.%d", &IIP1,&IIP2,&IIP3,&IIP4); According to the "%d.%d.%d.%d" format, the contents of STR are parsed out IIP1~IIP4

5.typedef

Role: Used to define a synonym for a type

such as: typedef double wages; Wages is a synonym for double

typedef wages Salary; Salary indirect is a synonym for double

6. Enum Enumeration

Such as:

typedef enum

{

Video_stream = 0x00; An enumeration member is a constant expression that can be used anywhere else where constant expressions are required

Audeo_stream =0x01;

Subpicture_stream = 0x02;

Unknown_stream = 0x03

Count_stream = 0x04;

} Streamtype;

Use of functions such as memset,strcpy, sprintf, etc. in C language

Related Article

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.