用c编写一个程序,总是出错,请大家帮忙看下哪里有错误?#include #include #include #include #include int main(){int fd ;if ((fd = serialOpen ("/dev/ttyAMA0",115200)) < 0){fprintf (stderr,"Unable to open serial device:%s\n",strerror (
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/15 06:58:34
用c编写一个程序,总是出错,请大家帮忙看下哪里有错误?#include #include #include #include #include int main(){int fd ;if ((fd = serialOpen ("/dev/ttyAMA0",115200)) < 0){fprintf (stderr,"Unable to open serial device:%s\n",strerror (
用c编写一个程序,总是出错,请大家帮忙看下哪里有错误?
#include
#include
#include
#include
#include
int main()
{
int fd ;
if ((fd = serialOpen ("/dev/ttyAMA0",115200)) < 0)
{
fprintf (stderr,"Unable to open serial device:%s\n",strerror (errno)) ;
return 1 ;
}
char str[] = serialGetchar();
int len=strlen(str);
char buf[100];
int a[4];
int i = 0;
while ( str[i] = '\0' )
{
if (isdigit(str[i]))
buf[i] = str[i];
else buf[i] = ' ';
++i;
}
buf[i] = '\0';
sscanf (buf,"%d %d %d %d",&a[0],&a[1],&a[2],&a[3]);
printf ("%d %d %d %d\n",a[0],a[1],a[2],a[3]);
return 0;
}
背景是这样的,蓝牙发送一串字符给单片机,例如g90s80x70y60,我想把数字分割出来,分别付给一个变量.
用c编写一个程序,总是出错,请大家帮忙看下哪里有错误?#include #include #include #include #include int main(){int fd ;if ((fd = serialOpen ("/dev/ttyAMA0",115200)) < 0){fprintf (stderr,"Unable to open serial device:%s\n",strerror (
char str[] = serialGetchar(); //这句改成以下:
char str[128];
strcpy( str,serialGetchar() );
另:你的fd没有用到啊,是不是在serialGetchar()函数中应用?没有函数说明,不能确定