int64_t t = 0LL;
const char* str = "0-20201219-130902-423.H264 2536 1608354627399 0.046892";
sscanf(s, "%*[^ ] %*[^ ] %" PRId64, &t);
可以得到1608354627399。
1.原样输出字符串:
printf("%s", str);
2. 输出指定长度的字符串, 超长时不截断, 不足时右对齐:
printf("%Ns", str); --N 为指定长度的10进制数值
3. 输出指定长度的字符串, 超长时不截断, 不足时左对齐:
printf("%-Ns", str); --N 为指定长度的10进制数值
4. 输出指定长度的字符串, 超长时截断, 不足时右对齐:
printf("%N.Ms", str); --N 为最终的字符串输出长度
--M 为从参数字符串中取出的子串长度
5. 输出指定长度的字符串, 超长时截断, 不足时左对齐是:
printf("%-N.Ms", str); --N 为最终的字符串输出长度
--M 为从参数字符串中取出的子串长度
#define PLOGI(fmt, args…) printf(“[%08p:%-16.16s]:” #fmt “\n”, syscall(SYS_gettid), FUNCTION, ##args)
#define PLOGD(fmt, args…) printf(“[%08p:%-16.16s]:” #fmt “\n”, syscall(SYS_gettid), FUNCTION, ##args)
#define PLOGE(fmt, args…) printf(“[%08p:%-16.16s]:” #fmt “\n”, syscall(SYS_gettid), FUNCTION, ##args)
// example: config write lockenv 118 3
int n = sscanf(ptr, "%[^ ] %[^ ] %[^ ] %[^ ] %[^\n]", config, write, group, key, value);
取字符串直到某个字符为止
博客给出了三个宏定义PLOGI、PLOGD、PLOGE,用于格式化输出信息,还提及取字符串直到某个字符为止的操作,整体围绕Linux相关编程内容。
3147





