【一段sscanf解析字符串的 ,蒙了】

bluestar2009 2018-03-12 04:59:21
#include <stdio.h>
#include <string.h>
struct dl
{
char CodecType[10];
char W[10];
char H[10];
char FPS[10];
char BR[10];
char HW[10];
char AG[10];
};
//主路大画面: [CodecType=5, W= 368, H= 640, FPS=132, BR= 781, HW= 0, AG= 0]
int main()
{
int i=0,j=0;
char str[256]={0},tmp[10]={0};
FILE *fp = NULL;
struct dl d={0};
fp = fopen("config.txt","r");
if (fp==NULL)
{
printf("open config failed\n");
return 1;
}
while (fgets(str,sizeof(str),fp))
{
if (strstr(str,"主路大画面")!=NULL)
{
printf("[%s]\n",str);
sscanf(str,"%*[^=]=%[^,],%*[^=]=%[^,],*%[^=]=%[^,],*%[^=]=%[^,],*%[^=]=%[^,],*[^=]=%[^,],*[^=]=%[^]]]"
,d.CodecType,tmp,d.W,d.H,d.FPS,d.BR,d.HW,d.AG);
printf("[%s] [%s] [%s] [%s] [%s] [%s] [%s]\n",d.CodecType,d.W,d.H,d.FPS,d.BR,d.HW,d.AG);
break;
}
}
return 0;
}

运行后是
[主路大画面: [CodecType=5, W= 368, H= 640, FPS=132, BR= 781, HW= 0, AG= 0]]
[5] [] [] [] [] [] []
Press any key to continue


...全文
254 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluestar2009 2018-03-12
  • 打赏
  • 举报
回复
写错了 手误 汗····

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧