linux 从串口读取数据时出现Segmentation fault 5
while(1){memset(buff,0,64);if((count=read(fd,buff,64))>0){for(i=0;i<count;i++)printf(...
while(1)
{ memset(buff,0,64);
if((count=read(fd,buff,64))>0)
{ for(i=0;i<count;i++)
printf("the received words are :%s",buff[i]);
}
} 展开
{ memset(buff,0,64);
if((count=read(fd,buff,64))>0)
{ for(i=0;i<count;i++)
printf("the received words are :%s",buff[i]);
}
} 展开
1个回答
展开全部
printf("the received words are :%s",buff[i]);
这句不对,buff[i]为一个字符或者是整数,与%s匹配,会造成访问地址为buff[i]的内存,致使发生段错误,改为:
printf("the received words are :%c",buff[i]); 或者:
printf("the received words are :%s",&buff[i]);
这句不对,buff[i]为一个字符或者是整数,与%s匹配,会造成访问地址为buff[i]的内存,致使发生段错误,改为:
printf("the received words are :%c",buff[i]); 或者:
printf("the received words are :%s",&buff[i]);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询