现在的位置: 首页 > 综合 > 正文

一些要打上几万遍养成好习惯的模式代码:对cwj说的,你有空就要打上好几百次哦,别忘记了

2013年12月04日 ⁄ 综合 ⁄ 共 689字 ⁄ 字号 评论关闭

1.new delete NULL的模式   C++:(帮助我们记住要释放空间)

father * fp=new son();

delete fp;

fp=NULL;

 

2.scanf  while getchar() \n 的模式 c: (帮助我们scanf的标准写法)

int iReturn = scanf("%d %f",&n,&f);//得到有效输入参数个数

while(getchar()!='\n');//清空缓冲区

if(2==iReturn){//判断是否正确输入}

 

3.malloc() free()   C : 空间的申请与释放

int *hep=(int*)malloc(sizeof(int)*1);

if(NULL==hep)return NULL;

 memset(hep,0,sizeof(int)*1);

 free(hep);

 hep=NULL;

 

4.fgets(str3,sizeof(str1),stdin);  通过fgets函数来达到限制输入字符的方式

   if(str[end-2]!='\0' && str[end-2]!='\n')while(getchar()!='\n');

 

5. #include<stdarg.h>  C:可变参数的实现

void printDouble(int size,...)

{

  double iVar;    int i=0;

  va_list list;

  va_start(list,size);

  while(i++<size){

  ivar=va_arg(list,double);

  printf("%lf",ivar);

  }

  printf("\n");

  va_end(list);

}

 

抱歉!评论已关闭.