一些 naive 的 Tips*

#Tip 1 - 四舍五入

floor(x+0.5) // 需要 #include <math.h>

 

#Tip 2 - continue 返回循环开头

在 for 循环中使用 continue; 可跳回循环开头。

#Tip 3 - *计时函数 clock()

printf("Time Used = %.2f",(double)clock() / CLOCK_PER_SEC);

来自《入门经典》page 26;

#Tip 4 - scanf() 拥有返回值

while (scanf("%d",&x)==1) {}

返回的值为成功输入的变量个数,可以无限制的输入,
当输入结束时, scanf 函数无法再次读取 x, 返回 0。

scanf 读取到空格或 tab 时,自动结束输入。

* scanf("&*d");

可输入一个数

但不赋给任何一个变量。

#Tip 5 - ctype.h 相关函数

 

isalnum()

//函数原型
#include<ctype.h>
int isalum(int c);

功能:如果输入的字符是字母(alphabet)或数字(number)返回真

isalpha()

//函数原型
#include<ctype.h>
int isalpha(int c);

功能:如果输入的字符是字母(alphabet)返回真

iscntrl()

//函数原型
#include<ctype.h>
int iscntrl(int c);

功能:如果输入的字符是控制字符(control)返回真

isdigit()

//函数原型
#include<ctype.h>
int isdigit(int c);

功能:如果输入的字符是数字(digit)返回真

isgraph()

//函数原型
#include<ctype.h>
int isgraph(int c);

功能:如果输入的字符是可显示字符(graphic)返回真,可显示字符是指除了空格之外的字符

islower()

//函数原型
#include<ctype.h>
int islower(int c);

功能:如果输入的字符是小写字母(lowercase)返回真

isprint()

//函数原型
#include<ctype.h>
int isprint(int c);

功能:如果输入的字符是可打印(printable)返回真,可打印字符是指包含空格在内的所有字符

ispunct()

//函数原型
#include<ctype.h>
int ispunct(int c);

功能:如果输入的字符不是空格也不是字母返回真

isspace()

//函数原型
#include<ctype.h>
int isspace(int c);

功能:如果输入的字符是空白字符返回真,空白字符包括'\t',' ', '\n' etc

isupper()

//函数原型
#include<ctype.h>
int isupper(int c);

功能:如果输入的字符是大写字母(uppercase)返回真

isexdigit

//函数原型
#include<ctype.h>
int isexdigit(int c);

功能:如果输入的字符是十六进制数字返回真

tolower()

//函数原型
#include<ctype.h>
int tolower(int c);

功能:把输入的大写字母转换成小写字母

toupper

//函数原型
#include<ctype.h>
int toupper(int c);

功能:把输入的小写字母转换成大写字母

以上来自 http://www.myexception.cn/c/2132417.html

 

posted @ 2018-01-25 14:28  soulwinter  阅读(212)  评论(0编辑  收藏  举报