?? s.htm
字號:
<PRE>/* input a salary as a float */
printf(" Salary : ");
scanf("%f", &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("\nPlease enter your name, age and salary\n");
scanf("%20s %d %lf", name, &age, &salary);
</PRE>
<PRE>/* Print out the data that was input */
printf("\n\nTable %s\n",label);
printf("Compiled by %s age %d $%15.2lf\n", name, age, salary);
printf("-----------------------------------------------------\n");
for (loop=0;loop printf("%4d | %-20s | %5d | %15.2lf\n",
loop + 1,
entry[loop].name,
entry[loop].age,
entry[loop].salary);
printf("-----------------------------------------------------\n");
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 "TEST.$$$" </PRE>
<PRE>int main(void)
{
struct stat statbuf;
FILE *stream; </PRE>
<PRE>/* open a file for update */
if ((stream = fopen(FILENAME, "w+")) == NULL)
{
fprintf(stderr, "Cannot open output file.\n");
return(1);
} </PRE>
<PRE>/* get information about the file */
stat(FILENAME, &statbuf); </PRE>
<PRE>fclose(stream); </PRE>
<PRE>/* display the information returned */
if (statbuf.st_mode & S_IFCHR)
printf("Handle refers to a device.\n");
if (statbuf.st_mode & S_IFREG)
printf("Handle refers to an ordinary file.\n");
if (statbuf.st_mode & S_IREAD)
printf("User has read permission on file.\n");
if (statbuf.st_mode & S_IWRITE)
printf("User has write permission on file.\n"); </PRE>
<PRE>printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev);
printf("Size of file in bytes: %ld\n", statbuf.st_size);
printf("Time file last opened: %s\n", ctime(&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("Status 87 before error: %x\n", _status87()); </PRE>
<PRE>x = y; /* <-- force an error to occur */
y = x; </PRE>
<PRE>printf("Status 87 after error : %x\n", _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(&t);
printf("Number of seconds since 1/1/1970 is: %ld\n", t);
printf("Local time is: %s", asctime(area)); </PRE>
<PRE>t++;
area = localtime(&t);
printf("Add a second: %s", asctime(area)); </PRE>
<PRE>t += 60;
area = localtime(&t);
printf("Add a minute: %s", asctime(area)); </PRE>
<PRE>t += 3600;
area = localtime(&t);
printf("Add an hour: %s", asctime(area)); </PRE>
<PRE>t += 86400L;
area = localtime(&t);
printf("Add a day: %s", asctime(area)); </PRE>
<PRE>t += 2592000L;
area = localtime(&t);
printf("Add a month: %s", asctime(area)); </PRE>
<PRE>t += 31536000L;
area = localtime(&t);
printf("Add a year: %s", 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 = "abcdefghi"; </PRE>
<PRE>stpcpy(string, str1);
printf("%s\n", 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 = " ", *c = "C++", *Borland = "Borland"; </PRE>
<PRE>strcpy(destination, Borland);
strcat(destination, blank);
strcat(destination, c); </PRE>
<PRE>printf("%s\n", 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, "This is a string");
ptr = strchr(string, c);
if (ptr)
printf("The character %c is at position: %d\n", c, ptr-string);
else
printf("The character was not found\n");
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 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
int ptr; </PRE>
<PRE>ptr = strcmp(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");
else
printf("buffer 2 is less than buffer 1\n"); </PRE>
<PRE>ptr = strcmp(buf2, buf3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3\n");
else
printf("buffer 2 is less than buffer 3\n"); </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 = "BBB", *buf2 = "bbb";
int ptr; </PRE>
<PRE>ptr = strcmpi(buf2, buf1); </PRE>
<PRE>if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n"); </PRE>
<PRE>if (ptr < 0)
printf("buffer 2 is less than buffer 1\n"); </PRE>
<PRE>if (ptr == 0)
printf("buffer 2 equals buffer 1\n"); </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 = "abcdefghi"; </PRE>
<PRE>strcpy(string, str1);
printf("%s\n", 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 = "1234567890";
char *string2 = "747DC8";
int length; </PRE>
<PRE>length = strcspn(string1, string2);
printf("Character where strings intersect is at position %d\n", 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 = "abcde"; </PRE>
<PRE>dup_str = strdup(string);
printf("%s\n", 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 = "BBB", *buf2 = "bbb";
int ptr; </PRE>
<PRE>ptr = stricmp(buf2, buf1); </PRE>
<PRE>if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n"); </PRE>
<PRE>if (ptr < 0)
printf("buffer 2 is less than buffer 1\n"); </PRE>
<PRE>if (ptr == 0)
printf("buffer 2 equals buffer 1\n"); </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("Error: %s\n", 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 = "BBB", *buf2 = "bbb";
int ptr; </PRE>
<PRE>ptr = strcmpi(buf2, buf1); </PRE>
<PRE>if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n"); </PRE>
<PRE>if (ptr < 0)
printf("buffer 2 is less than buffer 1\n"); </PRE>
<PRE>if (ptr == 0)
printf("buffer 2 equals buffer 1\n"); </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 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
int ptr; </PRE>
<PRE>ptr = strncmp(buf2,buf1,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");
else
printf("buffer 2 is less than buffer 1\n"); </PRE>
<PRE>ptr = strncmp(buf2,buf3,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3\n");
else
printf("buffer 2 is less than buffer 3\n"); </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 = "BBBccc", *buf2 = "bbbccc";
int ptr; </PRE>
<PRE>ptr = strncmpi(buf2,buf1,3); </PRE>
<PRE>if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n"); </PRE>
<PRE>if (ptr < 0)
printf("buffer 2 is less than buffer 1\n"); </PRE>
<PRE>if (ptr == 0)
printf("buffer 2 equals buffer 1\n"); </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 = "abcdefghi"; </PRE>
<PRE>strncpy(string, str1, 3);
string[3] = '\0';
printf("%s\n", 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 = "BBBccc", *buf2 = "bbbccc";
int ptr; </PRE>
<PRE>ptr = strnicmp(buf2, buf1, 3); </PRE>
<PRE>if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n"); </PRE>
<PRE>if (ptr < 0)
printf("buffer 2 is less than buffer 1\n"); </PRE>
<PRE>if (ptr == 0)
printf("buffer 2 equals buffer 1\n"); </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 = "abcdefghijklmnopqrstuvwxyz";
char letter = 'x'; </PRE>
<PRE>printf("string before strnset: %s\n", string);
strnset(string, letter, 13);
printf("string after strnset: %s\n", 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 = "abcdefghijklmnopqrstuvwxyz";
char *string2 = "onm";
char *ptr; </PRE>
<PRE>ptr = strpbrk(stri
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -