- sizeof的妙用
#define countof(a) (sizeof(a) / sizeof(*(a)))
#define TxBufferSize1 (countof(TxBuffer1) - 1) //去掉 '\0'
uint8_t TxBuffer1[] = "xxx";
uint8_t RxBuffer1[RxBufferSize1];
- 使用 %*c %*d 跳过一个字符/数据
- 用scanf循环接收数据到数组
int main()
{
int a[100];
int i = 0;
int ch;
while ((ch = fgetc(stdin)) != '\n') //stdin为键盘输入缓冲,定义于stdlib.h中
{
if (ch == ' ' || ch == ',') continue;
ungetc(ch, stdin); //将ch中字符退回数据流
scanf("%d", &a[i++]);
}
return 0;
}
或
int main()
{
int a[10];
int i = 0;
int ch;
while (scanf("%d%c", a + i++,ch) == 2)//scanf的返回值为成功输入的个数,此处或改为 !=0
{ if(ch=='\n')break; }
return 0;
}