strcpy and Strlen

Source: Internet
Author: User
Tags prototype definition

String.h:C language inside the function definition of the character array header file, commonly used functions have strlen, strcmp, strcpy and so on, in more detail can be in the Include folder to view the file.

The%c format corresponds to a single character, and the%s format corresponds to a string

char * strcpy (char *strdest,const char *strsrc)

{

assert ((strdest!=null) && (strsrc!=null));

Char *result=strdest;

while ((*strdest++=*strsrc++)! = ' + ');//Copy the end character of the string ' \ n '

return address;

}

int strlen (const char *STR)

{

ASSERT (Str!=null);

int len=0;

While (*str!= ')

{len++;} The end character of the string is not computed ' \ s '

return Len;

}

The macro in C macro Name: AssertFunction: Test a condition and possibly cause the program to terminate the Assert macro's prototype definition in <assert.h>, its role is to terminate the program execution if its condition returns an error, prototype definition:?
123456 #defineassert(expr)\((expr)\?__ASSERT_VOID_CAST(0)\:__assert_fail(__STRING(expr),__FILE__,__LINE__,__ASSERT_FUNCTION))/*DefinedInGlibc2.15*/
The role of assert is to evaluate the expression expr first, if its value is false (that is, 0), then it will print out the ASSERT content and __file__, __line__, __assert_function, and then execute abort () The function causes kernel to kill itself and coredump (whether to generate Coredump files, depending on the system configuration); otherwise, assert () has no effect. Macro assert () is generally used to confirm the normal operation of the program, where the expression construction is not a mistake for truth. After debugging is complete, you do not have to remove the ASSERT () statement from the source code because the macro ndebug definition is empty. [1]

One, what is Coredump

We often hear people say that the program core dropped, need to locate the solution, most of this refers to the corresponding program due to various anomalies or bugs in the process of abnormal exit or abort, and under certain conditions (why do we need to meet certain conditions?) The following analysis will produce a file called core.

Typically, the core file contains the program runtime memory, register state, stack pointers, memory management information and various function call stack information, we can understand that the program is the current state store to generate the first file, many of the program error will produce a core file, Through the tool analysis of this file, we can locate the program when the exception exits the corresponding stack call information, identify the problem and timely resolution.

Second, the storage location of the Coredump file

The default storage location of the core file and the corresponding executable program in the same directory, the file name is the core, you can see the following command where the core file exists:

Cat/proc/sys/kernel/core_pattern

The default value is the core

#include <iostream> using namespace std; char * strcpy (char *strdest,const char *strsrc)

{

ASSERT ((strdest!=null) && (strsrc!=null));

Char *result=strdest;

while ((*strdest++=*strsrc++)! = ' + ');//Copy the end character of the string ' \ n '

return address;

} int main () {char *str1= "22";   Char *str2= "3344";   Char *str3=strcpy (STR1,STR2);   cout<<*str3;  return 0; }

#include <string.h> #include <stdio.h>

int main () {char *str1= "22";   Char *str2= "3344";   Char *str3=strcpy (STR1,STR2);   printf ("%s", STR3); return 0; }

strcpy and Strlen

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.