Advance knowledge of software development (8) memset () and memcpy () function

Source: Internet
Author: User
Tags date count function prototype include printf

Software projects in the code, fewer than thousands of lines, many tens of thousands of lines, but not irregular to follow. After reading so much code, I found that two functions appear very frequently, and that is the memset () and memcpy () functions, which are often used in C language programming. After work, I looked up some information, and now make a brief description of them.

1. memset () function

(1) Function prototype

void *memset (void *dest, int c, size_t count).

(2) Function action

In MSDN, the function is described as: Sets buffers to a specified character, which is to set the cache to a special character. To put it simply, you set the value of the first count byte of the open memory space dest to value C.

(3) Application examples

/*************************************************************** * All rights reserved (C) 2014, Zhou Zhaoxiong.
    
* * File name: memset.c * Content Summary: For testing memset function * Other Description: No * current version: V1.0 * Author: Zhou * Completion Date: 20140329 * * Modify the Record 1://Modify history, including modified date, version number, modifier and modified content, etc. * Modified Date: * Version number: * Modified by: * Modified content: ******************
    
     
    
/#include <memory.h> #include <stdio.h>                       typedef signed Char INT8;                     Redefine data type typedef signed INT INT32; Redefining data Types/********************************************************************** * Function Description: main function * lose In parameter: no * output parameter: no * return value: No * other Description: No * Modified Date version number modify the content *----------------            --------------------------------------------------------------------------------------* 20140329 V1.0 Zhou create *******/INT32 Main (void) {INT8 szteststr[100
    
          
    
    ] = "AAAAAAAAAA";
    
          
    
    printf ("The original string is:%s\n", SZTESTSTR);     memset (szteststr, ' B ', 5);
    
     
    
    Call the Memset function printf ("The changed string is:%s\n", SZTESTSTR);
    
return 0; }

The output of the program is:

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/project/

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.