一、malloc(), 因为当内存分配完了后,就无法再分配空间了,所以malloc失败也是有的是,当malloc失败时返回NULL.
char *s = (void *)malloc(SIZE);
if(s == NULL)
{
printf("malloc failed !\n");
return -1
}
二、fopen() , 因为当文件不存在,或是打开的方式不对(没有权限时),则fopen失败是很经常的,当fopen失败时返回NULL.
FILE *fp;
fp = fopen("filename","a+");
if(fp == NULL)
{
printf("the file open failed !\n");
return -1;
}
三、当使用命令行参数时,要对参数的个数进行检验
int main(int argc , char **argv)
{
if(argc < 2)
{
printf("input the argc error ! \n");
return -1;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)