memset函数的用法及常见错误

本文介绍了memset函数的用途,包括bzero()函数的背景及其不推荐使用的原因。详细解析了memset()函数的功能,并指出错误用法,如不能用于非零或非-1的int数组初始化,以及ch参数的有效范围只限于0~255。同时提醒注意避免参数位置颠倒的常见错误。
摘要由CSDN通过智能技术生成

memset 函数的用法及常见错误

转载自https://blog.csdn.net/pugu12/article/details/46861923
转载自https://blog.csdn.net/qq_42991793/article/details/81751284
转载自https://baike.baidu.com/item/memset/4747579?fr=aladdin


bzero 函数和 memset 函数在功能上有相似之处,因此也做一个简单介绍。

1. bzero()函数

原型:extern void bzero(void *s, int n);   
功能:置字节字符串 s 的前 n 个字节为零且包括 ‘\0’ 。  
说明:bzero 无返回值,并且使用 strings.h 头文件,strings.h 曾经是 posix 标准的一部分,但是在 POSIX.1-2001 标准里面,这些函数被标记为了遗留函数而不推荐使用。在 POSIX.1-2008 标准里已经没有这些函数了。

操作实例:

#include <stdio.h>
#include <string.h>
int main(void)
{
   
	struct
	{
   
		int a;
		
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
获取USB摄像头的1080p的JPEG格式的图片20180608_1806.7z 电脑上的系统:ubuntu14.04 // http://www.linuxidc.com/Linux/2011-03/33020.htm // V4L2摄像头获取单幅图片测试程序(MMAP模式) // [日期:2011-03-06] 来源:Linux社区 作者:aokikyon [字体:大 中 小] // // #加了点注释 // // #Rockie Cheng // printf #include #include // memset #include #include #include #include // close write usleep read #include #include #include #include #include #include // mmap #include #include #include #include // pthread_create pthread_join #include #define CLEAR(x) memset (&(x), 0, sizeof (x)) #define REQ_COUNT 6 #define uchar unsigned char struct buffer { void * start; size_t length; }; static char * dev_name = "/dev/video0";//摄像头设备名 static int fd = -1; struct buffer * buffers = NULL; // static unsigned int n_buffers = 0; // 2012-7-13 11:33 camera flag // static int iFlagCamera = 0; volatile int iFlagCamera = 0; // 函数名称:thread1 // 函数功能:用于接受键盘的输入,之后通知thread2抓图 // 参数列表: // 返回值 : void thread1(void) { char ch; printf("\n !!!!Warning!!!!\n Max 1000 color bmp\n Input the char: \n"); printf("\n !!!!press o an capture 1 frame picture! \n"); printf("\n !!!!press t an capture 10 frame picture! \n"); printf("\n !!!!press h an capture 100 frame picture! \n"); while(1) { while((ch=getchar()) != '\n') { printf("%c\n", ch); if('o'==ch) { iFlagCamera = 1; printf("thread1=%d\n", iFlagCamera); } else if('t'==ch) { iFlagCamera = 10; printf("thread1=%d\n", iFlagCamera); } else if('h'==ch) { iFlagCamera = 101; printf("thread1=%d\n", iFlagCamera); } else if('q'==ch) { iFlagCamera = 10001; printf("thread1=%d\n", iFlagCamera
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值