编程札记

C

C库 limits.h

C库 limits.h #include <stdio.h> #include <limits.h> int main() { printf("The number of bits in a byte %d\n", CHAR_BIT); printf("The minimum value of SIGNED CHAR = %d\n", SCHAR_MIN); printf("The maximum value of SIGNED CHAR = %d\n", SCHAR_MAX); printf("The maximum value of UNSIGNED CHAR = %d\n", UCHAR_MAX); printf("The minimum value of SHORT INT = %d\n", SHRT_MIN); printf("The maximum value of SHORT INT = %d\n", SHRT_MAX); printf("The minimum value of INT = %d\n", INT_MIN); printf("The maximum value of INT = %d\n", INT_MAX); printf("The minimum value of CHAR = %d\n", CHAR_MIN); printf("The maximum value of CHAR = %d\n", CHAR_MAX); printf("The minimum value of LONG = %ld\n", LONG_MIN); printf("The maximum value of LONG = %ld\n", LONG_MAX); return(0); }

阅读全文 ↗
C

C库 float.h

C库 float.h #include <stdio.h> #include <float.h> int main () { printf("The maximum value of float = %.10e\n", FLT_MAX); printf("The minimum value of float = %.10e\n", FLT_MIN); printf("The number of digits in the number = %.10e\n", FLT_MANT_DIG); }

阅读全文 ↗
C

C库宏 ERANGE

C库宏 ERANGE #include <stdio.h> #include <errno.h> #include <math.h> int main () { double x; double value; x = 2.000000; value = log(x); if( errno == ERANGE ) { printf("Log(%f) is out of range\n", x); } else { printf("Log(%f) = %f\n", x, value); } x = 1.000000; value = log(x); if( errno == ERANGE ) { printf("Log(%f) is out of range\n", x); } else { printf("Log(%f) = %f\n", x, value); } x = 0.000000; value = log(x); if( errno == ERANGE ) { printf("Log(%f) is out of range\n", x); } else { printf("Log(%f) = %f\n", x, value); } return 0; }

阅读全文 ↗
C

C库宏 EDOM

C库宏 EDOM #include <stdio.h> #include <errno.h> #include <math.h> int main () { double val; errno = 0; val = sqrt(-10); if(errno == EDOM) { printf("Invalid value \n"); } else { printf("Valid value\n"); } errno = 0; val = sqrt(10); if(errno == EDOM) { printf("Invalid value\n"); } else { printf("Valid value\n"); } return(0); }

阅读全文 ↗
C

C库宏 errno

C库宏 errno #include <stdio.h> #include <errno.h> #include <string.h> extern int errno ; int main () { FILE *fp; fp = fopen("file.txt", "r"); if( fp == NULL ) { fprintf(stderr, "Value of errno: %d\n", errno); fprintf(stderr, "Error opening file: %s\n", strerror(errno)); } else { fclose(fp); } return(0); }

阅读全文 ↗
C

C库函数 toupper()

C库函数 toupper() #include <stdio.h> #include <ctype.h> int main () { int i = 0; char c; char str[] = "Tutorials Point"; while(str[i]) { putchar (toupper(str[i])); i++; } return(0); }

阅读全文 ↗
C

C库函数 tolower()

C库函数 tolower() #include <stdio.h> #include <ctype.h> int main () { int i = 0; char c; char str[] = "TUTORIALS POINT"; while( str[i] ) { putchar(tolower(str[i])); i++; } return(0); }

阅读全文 ↗
C

C库函数 isxdigit()

C库函数 isxdigit() #include <stdio.h> #include <ctype.h> int main () { char var1[] = "tuts"; char var2[] = "0xE"; if( isxdigit(var1[0]) ) { printf("var1 = |%s| is hexadecimal character\n", var1 ); } else { printf("var1 = |%s| is not hexadecimal character\n", var1 ); } if( isxdigit(var2[0] )) { printf("var2 = |%s| is hexadecimal character\n", var2 ); } else { printf("var2 = |%s| is not hexadecimal character\n", var2 ); } return(0); }

阅读全文 ↗
C

C库函数 isupper()

C库函数 isupper() #include <stdio.h> #include <ctype.h> int main () { int var1 = 'M'; int var2 = 'm'; int var3 = '3'; if( isupper(var1) ) { printf("var1 = |%c| is uppercase character\n", var1 ); } else { printf("var1 = |%c| is not uppercase character\n", var1 ); } if( isupper(var2) ) { printf("var2 = |%c| is uppercase character\n", var2 ); } else { printf("var2 = |%c| is not uppercase character\n", var2 ); } if( isupper(var3) ) { printf("var3 = |%c| is uppercase character\n", var3 ); } else { printf("var3 = |%c| is not uppercase character\n", var3 ); } return(0); }

阅读全文 ↗
C

C库函数 isspace()

C库函数 isspace() #include <stdio.h> #include <ctype.h> int main () { int var1 = 't'; int var2 = '1'; int var3 = ' '; if( isspace(var1) ) { printf("var1 = |%c| is a white-space character\n", var1 ); } else { printf("var1 = |%c| is not a white-space character\n", var1 ); } if( isspace(var2) ) { printf("var2 = |%c| is a white-space character\n", var2 ); } else { printf("var2 = |%c| is not a white-space character\n", var2 ); } if( isspace(var3) ) { printf("var3 = |%c| is a white-space character\n", var3 ); } else { printf("var3 = |%c| is not a white-space character\n", var3 ); } return(0); }

阅读全文 ↗
C

C库函数 ispunct()

C库函数 ispunct() #include <stdio.h> #include <ctype.h> int main () { int var1 = 't'; int var2 = '1'; int var3 = '/'; int var4 = ' '; if( ispunct(var1) ) { printf("var1 = |%c| is a punctuation character\n", var1 ); } else { printf("var1 = |%c| is not a punctuation character\n", var1 ); } if( ispunct(var2) ) { printf("var2 = |%c| is a punctuation character\n", var2 ); } else { printf("var2 = |%c| is not a punctuation character\n", var2 ); } if( ispunct(var3) ) { printf("var3 = |%c| is a punctuation character\n", var3 ); } else { printf("var3 = |%c| is not a punctuation character\n", var3 ); } if( ispunct(var4) ) { printf("var4 = |%c| is a punctuation character\n", var4 ); } else { printf("var4 = |%c| is not a punctuation character\n", var4 ); } return(0); }

阅读全文 ↗
C

C库函数 isprint()

C库函数 isprint() #include <stdio.h> #include <ctype.h> int main () { int var1 = 'k'; int var2 = '8'; int var3 = '\t'; int var4 = ' '; if( isprint(var1) ) { printf("var1 = |%c| can be printed\n", var1 ); } else { printf("var1 = |%c| can't be printed\n", var1 ); } if( isprint(var2) ) { printf("var2 = |%c| can be printed\n", var2 ); } else { printf("var2 = |%c| can't be printed\n", var2 ); } if( isprint(var3) ) { printf("var3 = |%c| can be printed\n", var3 ); } else { printf("var3 = |%c| can't be printed\n", var3 ); } if( isprint(var4) ) { printf("var4 = |%c| can be printed\n", var4 ); } else { printf("var4 = |%c| can't be printed\n", var4 ); } return(0); }

阅读全文 ↗