sscanf提取相应字符到数组

代码如下

复制代码
#include<stdio.h>
#include<string.h>

int main(int argc, char const *argv[])
{
    char buf[128] = {0};
    int m1 = 0, m2 = 0;
    int s1 = 0, s2 = 0;
    char lrc[128] = "";
    sscanf("[02:16.33][04:11.44]我想大声宣布对你恋恋不舍","[%*1d%d",&m1);
    sscanf("[02:16.33][04:11.44]我想大声宣布对你恋恋不舍","[%*d%*[^4]%d",&m2);
    sscanf("[02:16.33][04:11.44]我想大声宣布对你恋恋不舍","%*[^:]%*c%2d",&s1);
    sscanf("[02:16.33][04:11.44]我想大声宣布对你恋恋不舍","%*[^:]%*c%*[^:]%*c%2d",&s2);
    sscanf("[02:16.33][04:11.44]我想大声宣布对你恋恋不舍","%*20s%s",lrc);    
    printf("%d秒打印歌词%s\n",m1*60+s1,lrc);
    printf("%d秒打印歌词%s\n",m2*60+s2,lrc);
    return 0;
}

运行结果如下

相关推荐
Flash.kkl9 分钟前
Linux——进程信号
运维·服务器
苏宸啊1 小时前
Linux权限
linux·运维·服务器
Gofarlic_oms12 小时前
Windchill用户登录与模块访问失败问题排查与许可证诊断
大数据·运维·网络·数据库·人工智能
我是小疯子662 小时前
Python变量赋值陷阱:浅拷贝VS深拷贝
java·服务器·数据库
xqhoj2 小时前
Linux——make、makefile
linux·运维·服务器
文亭湖畔程序猿2 小时前
Debian 12 日常命令 & nano 快捷键速查表
运维·debian
张童瑶2 小时前
Linux 在线安装编译Python3.11
linux·运维·python3.11
ziqibit2 小时前
debian Live with Persistence 持久化U盘的debian系统
运维·debian
Shi_haoliu2 小时前
SolidTime 在 Rocky Linux 9.5 上的完整部署流程
linux·运维·nginx·postgresql·vue·php·laravel
lifejump2 小时前
Pikachu | XXE
服务器·web安全·网络安全·安全性测试