Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the function prototypes in C language?

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail what are the function prototypes in the C language, and the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Examples are as follows:

/ / strcat (dest,src) add the string referred to by src to the end of dest (overwrite the'\ 0' at the end of dest) and add'\ 0'char * strcat (char * strDest, const char * strSrc) {char * res=strDest; assert ((strstrDestrated null) & & (strSrcencoded null)); while (* strDest) strDest++; while (* strDest=*strSrc) {strDest++; strSrc++;} return res } / / strcpy (dest,src) copy the string that starts with the src address and contains the null Terminator to the address space char * strcpy (char * strDest, const char * strSrc) {char * res=strDest; assert ((strDestrated termination null) & & (strSrcencoded termination null)); while ((* strDest=*strSrc)! ='\ 0') {strDest++; strSrc++;} return res;}

1. The Strcat function prototype is as follows:

Char * strcat (char * strDest, const char * strScr) / / adds the source string to const, indicating that it is the input parameter {char * address = strDest; / / if the statement is placed after assert, the compilation error assert ((strDest! = NULL) & & (strScr! = NULL)) / / adding non-zero assertions to source and destination addresses that while (* strDest) / / is a simplified form of while (* strDestrated destination addresses) {/ / if you use while (* strDest++), you will make an error because + + is not constrained by cyclic strDest++; / /. So + + inside the loop; because if * strDest ends with} / / to the end flag of the string'/ 0'. While (* strDest++ = * strScr++) {NULL; / / you can use + + in this loop condition,} / / you can add the statement * strDest='/0'; here. Is it necessary? Return address; / / to implement chained operation, return destination address}

The following is an example of debugging in VC6.0, where the function name is replaced by strcata.

# include # include char * strcata (char * strDest,const char * strScr) {char * address = strDest; assert ((strDest! = NULL) & & (strScr! = NULL)); while (* strDest) {strDest++;} while (* strDest++ = * strScr++) {NULL;} return address;} void main () {char str1 [100] = {"I love"}; char str2 [50] = {"China"} Printf ("% Szone", strcata (str1,str2));}

2. The prototype of Strcpy function is as follows:

Char * strcpy (char * strDest, const char * strScr) {char * address=strDest; assert ((strDest! = NULL) & & (strScr! = NULL)); while (* strScr) / / is a simplified form of while (* strScr! ='/ 0') {* strDest++ = * strScr++;} * strDest ='/ 0string; / / when the length of the strScr string is less than the original strDest string length return address; / /, an error will occur if the statement is not changed. }

The following is an example of debugging in VC6.0, where the function name is replaced by strcpya.

# include # include char * strcpya (char * strDest, const char * strScr) {char * address = strDest; assert ((strDest! = NULL) & & (strScr! = NULL)); while (* strScr) {* strDest++ = * strScr++;} * strDest ='/ 0mm; return address;} void main () {char str1 [100] = {"I love"}; char str2 [50] = {"China"} Printf ("% Szone", strcpya (str1,str2));}

3. The prototype of Strcmp function is as follows:

Int strcmp (const char * str1,const char * str2) {int len = 0; assert ((str1! ='/ 0') & & (str2! ='/ 0')); while (* str1 & & * str2 & & (* str1 = = * str2)) {str1++; str2++;} return * str1-*str2;}

The following is an example of debugging in VC6.0, where the function name is replaced by strcmpa.

# include # include int strcmpa (const char * str1,const char * str2) {int len = 0; assert ((str1! ='/ 0') & & (str2! ='/ 0')); while (* str1 & & * str2 & & (* str1==*str2)) {str1++; str2++;} return * str1-*str2;} void main () {char str1 [100] = {"I love"} Char str2 [50] = {"China"}; printf ("% dzone", strcmpa (str1,str2));}

4. The prototype of Strlen function is as follows:

Int strlen (const char * str) {int len = 0; assert (str! = NULL); while (* str++) {len++;} return len;}

The following is an example of debugging in VC6.0, where the function name is replaced by strlena.

# include # include int strlena (const char * str) {int len = 0; assert (str! = NULL); while (* str++) {len++;} return len;} void main () {char str1 [50] = {"I love"}; char str2 [50] = {"China"}; printf ("% dsea", strlena (str1)) What about the C language function prototype is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report