⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s.htm

📁 C语言函数库,包含所有的C语言函数
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<PRE>/* input a salary as a float */ 
printf(&quot; Salary : &quot;); 
scanf(&quot;%f&quot;, &amp;entry[loop].salary); 
fflush(stdin); /* flush the input stream in case of bad input */ 
} </PRE>
<PRE>/* Input a name, age and salary as a string, integer, and double */ 
printf(&quot;\nPlease enter your name, age and salary\n&quot;); 
scanf(&quot;%20s %d %lf&quot;, name, &amp;age, &amp;salary); 
</PRE>
<PRE>/* Print out the data that was input */ 
printf(&quot;\n\nTable %s\n&quot;,label); 
printf(&quot;Compiled by %s age %d $%15.2lf\n&quot;, name, age, salary); 
printf(&quot;-----------------------------------------------------\n&quot;); 
for (loop=0;loop printf(&quot;%4d | %-20s | %5d | %15.2lf\n&quot;, 
loop + 1, 
entry[loop].name, 
entry[loop].age, 
entry[loop].salary); 
printf(&quot;-----------------------------------------------------\n&quot;); 
return 0; 
} 

</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> stat </font>
功 能: 读取打开文件信息 
用 法: int stat(char *pathname, struct stat *buff); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>#define FILENAME &quot;TEST.$$$&quot; </PRE>
<PRE>int main(void) 
{ 
struct stat statbuf; 
FILE *stream; </PRE>
<PRE>/* open a file for update */ 
if ((stream = fopen(FILENAME, &quot;w+&quot;)) == NULL) 
{ 
fprintf(stderr, &quot;Cannot open output file.\n&quot;); 
return(1); 
} </PRE>
<PRE>/* get information about the file */ 
stat(FILENAME, &amp;statbuf); </PRE>
<PRE>fclose(stream); </PRE>
<PRE>/* display the information returned */ 
if (statbuf.st_mode &amp; S_IFCHR) 
printf(&quot;Handle refers to a device.\n&quot;); 
if (statbuf.st_mode &amp; S_IFREG) 
printf(&quot;Handle refers to an ordinary file.\n&quot;); 
if (statbuf.st_mode &amp; S_IREAD) 
printf(&quot;User has read permission on file.\n&quot;); 
if (statbuf.st_mode &amp; S_IWRITE) 
printf(&quot;User has write permission on file.\n&quot;); </PRE>
<PRE>printf(&quot;Drive letter of file: %c\n&quot;, 'A'+statbuf.st_dev); 
printf(&quot;Size of file in bytes: %ld\n&quot;, statbuf.st_size); 
printf(&quot;Time file last opened: %s\n&quot;, ctime(&amp;statbuf.st_ctime)); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">_status87 </font>
功 能: 取浮点状态 
用 法: unsigned int _status87(void); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
float x; 
double y = 1.5e-100; </PRE>
<PRE>printf(&quot;Status 87 before error: %x\n&quot;, _status87()); </PRE>
<PRE>x = y; /* &lt;-- force an error to occur */ 
y = x; </PRE>
<PRE>printf(&quot;Status 87 after error : %x\n&quot;, _status87()); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">stime </font>
功 能: 设置时间 
用 法: int stime(long *tp); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
time_t t; 
struct tm *area; </PRE>
<PRE>t = time(NULL); 
area = localtime(&amp;t); 
printf(&quot;Number of seconds since 1/1/1970 is: %ld\n&quot;, t); 
printf(&quot;Local time is: %s&quot;, asctime(area)); </PRE>
<PRE>t++; 
area = localtime(&amp;t); 
printf(&quot;Add a second: %s&quot;, asctime(area)); </PRE>
<PRE>t += 60; 
area = localtime(&amp;t); 
printf(&quot;Add a minute: %s&quot;, asctime(area)); </PRE>
<PRE>t += 3600; 
area = localtime(&amp;t); 
printf(&quot;Add an hour: %s&quot;, asctime(area)); </PRE>
<PRE>t += 86400L; 
area = localtime(&amp;t); 
printf(&quot;Add a day: %s&quot;, asctime(area)); </PRE>
<PRE>t += 2592000L; 
area = localtime(&amp;t); 
printf(&quot;Add a month: %s&quot;, asctime(area)); </PRE>
<PRE>t += 31536000L; 
area = localtime(&amp;t); 
printf(&quot;Add a year: %s&quot;, asctime(area)); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">stpcpy </font>
功 能: 拷贝一个字符串到另一个 
用 法: char *stpcpy(char *destin, char *source); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char string[10]; 
char *str1 = &quot;abcdefghi&quot;; </PRE>
<PRE>stpcpy(string, str1); 
printf(&quot;%s\n&quot;, string); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strcat </font>
功 能: 字符串拼接函数 
用 法: char *strcat(char *destin, char *source); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char destination[25]; 
char *blank = &quot; &quot;, *c = &quot;C++&quot;, *Borland = &quot;Borland&quot;; </PRE>
<PRE>strcpy(destination, Borland); 
strcat(destination, blank); 
strcat(destination, c); </PRE>
<PRE>printf(&quot;%s\n&quot;, destination); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strchr </font>
功 能: 在一个串中查找给定字符的第一个匹配之处\ 
用 法: char *strchr(char *str, char c); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char string[15]; 
char *ptr, c = 'r'; </PRE>
<PRE>strcpy(string, &quot;This is a string&quot;); 
ptr = strchr(string, c); 
if (ptr) 
printf(&quot;The character %c is at position: %d\n&quot;, c, ptr-string); 
else 
printf(&quot;The character was not found\n&quot;); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strcmp </font>
功 能: 串比较 
用 法: int strcmp(char *str1, char *str2); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *buf1 = &quot;aaa&quot;, *buf2 = &quot;bbb&quot;, *buf3 = &quot;ccc&quot;; 
int ptr; </PRE>
<PRE>ptr = strcmp(buf2, buf1); 
if (ptr &gt; 0) 
printf(&quot;buffer 2 is greater than buffer 1\n&quot;); 
else 
printf(&quot;buffer 2 is less than buffer 1\n&quot;); </PRE>
<PRE>ptr = strcmp(buf2, buf3); 
if (ptr &gt; 0) 
printf(&quot;buffer 2 is greater than buffer 3\n&quot;); 
else 
printf(&quot;buffer 2 is less than buffer 3\n&quot;); </PRE>
<PRE>return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strncmpi </font>
功 能: 将一个串中的一部分与另一个串比较, 不管大小写 
用 法: int strncmpi(char *str1, char *str2, unsigned maxlen); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *buf1 = &quot;BBB&quot;, *buf2 = &quot;bbb&quot;; 
int ptr; </PRE>
<PRE>ptr = strcmpi(buf2, buf1); </PRE>
<PRE>if (ptr &gt; 0) 
printf(&quot;buffer 2 is greater than buffer 1\n&quot;); </PRE>
<PRE>if (ptr &lt; 0) 
printf(&quot;buffer 2 is less than buffer 1\n&quot;); </PRE>
<PRE>if (ptr == 0) 
printf(&quot;buffer 2 equals buffer 1\n&quot;); </PRE>
<PRE>return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strcpy </font>
功 能: 串拷贝 
用 法: char *strcpy(char *str1, char *str2); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char string[10]; 
char *str1 = &quot;abcdefghi&quot;; </PRE>
<PRE>strcpy(string, str1); 
printf(&quot;%s\n&quot;, string); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strcspn </font>
功 能: 在串中查找第一个给定字符集内容的段 
用 法: int strcspn(char *str1, char *str2); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *string1 = &quot;1234567890&quot;; 
char *string2 = &quot;747DC8&quot;; 
int length; </PRE>
<PRE>length = strcspn(string1, string2); 
printf(&quot;Character where strings intersect is at position %d\n&quot;, length); </PRE>
<PRE>return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strdup </font>
功 能: 将串拷贝到新建的位置处 
用 法: char *strdup(char *str); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *dup_str, *string = &quot;abcde&quot;; </PRE>
<PRE>dup_str = strdup(string); 
printf(&quot;%s\n&quot;, dup_str); 
free(dup_str); </PRE>
<PRE>return 0; 
} 


</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> stricmp </font>
功 能: 以大小写不敏感方式比较两个串 
用 法: int stricmp(char *str1, char *str2); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *buf1 = &quot;BBB&quot;, *buf2 = &quot;bbb&quot;; 
int ptr; </PRE>
<PRE>ptr = stricmp(buf2, buf1); </PRE>
<PRE>if (ptr &gt; 0) 
printf(&quot;buffer 2 is greater than buffer 1\n&quot;); </PRE>
<PRE>if (ptr &lt; 0) 
printf(&quot;buffer 2 is less than buffer 1\n&quot;); </PRE>
<PRE>if (ptr == 0) 
printf(&quot;buffer 2 equals buffer 1\n&quot;); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strerror </font>
功 能: 返回指向错误信息字符串的指针 
用 法: char *strerror(int errnum); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *buffer; 
buffer = strerror(errno); 
printf(&quot;Error: %s\n&quot;, buffer); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strcmpi </font>
功 能: 将一个串与另一个比较, 不管大小写 
用 法: int strcmpi(char *str1, char *str2); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *buf1 = &quot;BBB&quot;, *buf2 = &quot;bbb&quot;; 
int ptr; </PRE>
<PRE>ptr = strcmpi(buf2, buf1); </PRE>
<PRE>if (ptr &gt; 0) 
printf(&quot;buffer 2 is greater than buffer 1\n&quot;); </PRE>
<PRE>if (ptr &lt; 0) 
printf(&quot;buffer 2 is less than buffer 1\n&quot;); </PRE>
<PRE>if (ptr == 0) 
printf(&quot;buffer 2 equals buffer 1\n&quot;); </PRE>
<PRE>return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strncmp </font>
功 能: 串比较 
用 法: int strncmp(char *str1, char *str2, int maxlen); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) </PRE>
<PRE>{ 
char *buf1 = &quot;aaabbb&quot;, *buf2 = &quot;bbbccc&quot;, *buf3 = &quot;ccc&quot;; 
int ptr; </PRE>
<PRE>ptr = strncmp(buf2,buf1,3); 
if (ptr &gt; 0) 
printf(&quot;buffer 2 is greater than buffer 1\n&quot;); 
else 
printf(&quot;buffer 2 is less than buffer 1\n&quot;); </PRE>
<PRE>ptr = strncmp(buf2,buf3,3); 
if (ptr &gt; 0) 
printf(&quot;buffer 2 is greater than buffer 3\n&quot;); 
else 
printf(&quot;buffer 2 is less than buffer 3\n&quot;); </PRE>
<PRE>return(0); 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strncmpi </font>
功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写 
用 法: int strncmpi(char *str1, char *str2); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *buf1 = &quot;BBBccc&quot;, *buf2 = &quot;bbbccc&quot;; 
int ptr; </PRE>
<PRE>ptr = strncmpi(buf2,buf1,3); </PRE>
<PRE>if (ptr &gt; 0) 
printf(&quot;buffer 2 is greater than buffer 1\n&quot;); </PRE>
<PRE>if (ptr &lt; 0) 
printf(&quot;buffer 2 is less than buffer 1\n&quot;); </PRE>
<PRE>if (ptr == 0) 
printf(&quot;buffer 2 equals buffer 1\n&quot;); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strncpy </font>
功 能: 串拷贝 
用 法: char *strncpy(char *destin, char *source, int maxlen); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char string[10]; 
char *str1 = &quot;abcdefghi&quot;; </PRE>
<PRE>strncpy(string, str1, 3); 
string[3] = '\0'; 
printf(&quot;%s\n&quot;, string); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strnicmp </font>
功 能: 不注重大小写地比较两个串 
用 法: int strnicmp(char *str1, char *str2, unsigned maxlen); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *buf1 = &quot;BBBccc&quot;, *buf2 = &quot;bbbccc&quot;; 
int ptr; </PRE>
<PRE>ptr = strnicmp(buf2, buf1, 3); </PRE>
<PRE>if (ptr &gt; 0) 
printf(&quot;buffer 2 is greater than buffer 1\n&quot;); </PRE>
<PRE>if (ptr &lt; 0) 
printf(&quot;buffer 2 is less than buffer 1\n&quot;); </PRE>
<PRE>if (ptr == 0) 
printf(&quot;buffer 2 equals buffer 1\n&quot;); </PRE>
<PRE>return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strnset </font>
功 能: 将一个串中的所有字符都设为指定字符 
用 法: char *strnset(char *str, char ch, unsigned n); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *string = &quot;abcdefghijklmnopqrstuvwxyz&quot;; 
char letter = 'x'; </PRE>
<PRE>printf(&quot;string before strnset: %s\n&quot;, string); 
strnset(string, letter, 13); 
printf(&quot;string after strnset: %s\n&quot;, string); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">strpbrk </font>
功 能: 在串中查找给定字符集中的字符 
用 法: char *strpbrk(char *str1, char *str2); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *string1 = &quot;abcdefghijklmnopqrstuvwxyz&quot;; 
char *string2 = &quot;onm&quot;; 
char *ptr; </PRE>
<PRE>ptr = strpbrk(stri

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -