gpt4 book ai didi

c - 在c编程中将字符串标记为所需长度?

转载 作者:行者123 更新时间:2023-11-30 17:59:48 25 4
gpt4 key购买 nike

如何将字符串(存储在 fgets() 函数中)标记为各种所需的大小?这些值之间没有任何分隔字符(\n,,,:,:,等)。该字符串是

"ABCD 1234 EFG56H1.223.445.66 J"

我希望生成的 token 应该看起来像

"ABCD" " 1234" " "/reading the space as a character/ "EF" "56" "H" "1.22"/(.)dot also a character/ "3.44" "5.66"

如何使用 strtok 函数执行此操作?

这道题实际上是用C从PDB文件中提取ATOM记录。

最佳答案

您可以简单地使用 sscanf

char a[100],b[100],c[100],d[100],e[100],f[100],g[100],h[100];
sscanf("ABCD 1234 EFG56H1.223.445.66 J","%s%s%2s%*1s%2s%1s%4s%4s%4s",a,b,c,d,e,f,g,h);

关于c - 在c编程中将字符串标记为所需长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11102812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com