{"id":40256,"date":"2023-10-04T01:01:09","date_gmt":"2023-10-03T17:01:09","guid":{"rendered":"https:\/\/www.techphant.cn\/?p=40256"},"modified":"2023-10-04T01:01:09","modified_gmt":"2023-10-03T17:01:09","slug":"shsyfydhqd","status":"publish","type":"post","link":"https:\/\/www.techphant.cn\/blog\/40256.html","title":{"rendered":"sscanf\u51fd\u6570\uff1a\u7528\u6cd5\u3001\u4f18\u70b9\u548c\u7f3a\u70b9"},"content":{"rendered":"
sscanf\u51fd\u6570\u662f\u4e00\u79cdC\u8bed\u8a00\u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u4ece\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u51fa\u6307\u5b9a\u7684\u6570\u636e\u3002\u5b83\u4e0escanf\u51fd\u6570\u7684\u529f\u80fd\u7c7b\u4f3c\uff0c\u4f46\u662f\u5b83\u66f4\u52a0\u7075\u6d3b\uff0c\u53ef\u4ee5\u5904\u7406\u66f4\u591a\u590d\u6742\u7684\u6570\u636e\u7c7b\u578b\u3002\u672c\u6587\u5c06\u4ecb\u7ecdsscanf\u51fd\u6570\u7684\u7528\u6cd5\uff0c\u4ee5\u53ca\u5b83\u7684\u4f18\u70b9\u548c\u7f3a\u70b9\u3002<\/p>\n
sscanf\u51fd\u6570\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n
int sscanf(const char *str, const char *format, ...);<\/pre>\n\u5176\u4e2d\uff0cstr\u662f\u8981\u89e3\u6790\u7684\u5b57\u7b26\u4e32\uff0cformat\u662f\u6307\u5b9a\u683c\u5f0f\uff0c…\u662f\u53ef\u53d8\u53c2\u6570\uff0c\u7528\u4e8e\u63a5\u53d7\u89e3\u6790\u51fa\u6765\u7684\u6570\u636e\u3002<\/p>\n
sscanf\u51fd\u6570\u53ef\u4ee5\u89e3\u6790\u51fa\u591a\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u6574\u578b\u3001\u6d6e\u70b9\u578b\u3001\u5b57\u7b26\u578b\u3001\u5b57\u7b26\u4e32\u7b49\u3002\u4f8b\u5982\uff0c\u5982\u679c\u8981\u89e3\u6790\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n
#include#include
<\/p> int main()<\/p>
{<\/p>
char str[] = \"123 4.56 hello\";<\/p>
int a;<\/p>
float b;<\/p>
char c[20];<\/p>
sscanf(str, \"%d %f %s\", &a, &b, c);<\/p>
printf(\"a=%d, b=%f, c=%sn\", a, b, c);<\/p> }<\/pre>\n
\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u89e3\u6790\u51fa\u5b57\u7b26\u4e32\u4e2d\u7684\u4e09\u4e2a\u6570\u636e\uff1aa=123\uff0cb=4.56\uff0cc=”hello”\u3002<\/p>\n
sscanf\u51fd\u6570\u7684\u4f18\u70b9<\/h2>\n
sscanf\u51fd\u6570\u7684\u4f18\u70b9\u6709\u5f88\u591a\uff1a<\/p>\n
\n
- \u5b83\u53ef\u4ee5\u89e3\u6790\u51fa\u591a\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u6bd4\u5982\u6574\u578b\u3001\u6d6e\u70b9\u578b\u3001\u5b57\u7b26\u578b\u3001\u5b57\u7b26\u4e32\u7b49\u3002<\/li>\n
- \u5b83\u53ef\u4ee5\u4ece\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u51fa\u6307\u5b9a\u7684\u6570\u636e\uff0c\u800c\u4e0d\u9700\u8981\u4f7f\u7528\u591a\u4f59\u7684\u5b57\u7b26\u3002<\/li>\n
- \u5b83\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u5904\u7406\u590d\u6742\u7684\u5b57\u7b26\u4e32\u3002<\/li>\n
- \u5b83\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u636e\u8f6c\u6362\u6210\u6307\u5b9a\u7684\u683c\u5f0f\uff0c\u6bd4\u5982\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u8f6c\u6362\u6210\u6574\u578b\u3002<\/li>\n<\/ul>\n
sscanf\u51fd\u6570\u7684\u7f3a\u70b9<\/h2>\n
sscanf\u51fd\u6570\u4e5f\u6709\u4e00\u4e9b\u7f3a\u70b9\uff1a<\/p>\n
\n
- \u5b83\u53ea\u80fd\u4ece\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u51fa\u6307\u5b9a\u7684\u6570\u636e\uff0c\u800c\u4e0d\u80fd\u63d0\u53d6\u51fa\u4efb\u610f\u4f4d\u7f6e\u7684\u6570\u636e\u3002<\/li>\n
- \u5b83\u4e0d\u80fd\u5904\u7406\u591a\u884c\u5b57\u7b26\u4e32\uff0c\u53ea\u80fd\u5904\u7406\u5355\u884c\u5b57\u7b26\u4e32\u3002<\/li>\n
- \u5b83\u4e0d\u80fd\u5904\u7406\u52a8\u6001\u53d8\u5316\u7684\u5b57\u7b26\u4e32\uff0c\u53ea\u80fd\u5904\u7406\u9759\u6001\u7684\u5b57\u7b26\u4e32\u3002<\/li>\n
- \u5b83\u4e0d\u80fd\u5904\u7406\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53ea\u80fd\u5904\u7406\u7b80\u5355\u7684\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<\/ul>\n
\u603b\u4e4b\uff0csscanf\u51fd\u6570\u662f\u4e00\u79cd\u5f3a\u5927\u7684C\u8bed\u8a00\u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u51fa\u6307\u5b9a\u7684\u6570\u636e\uff0c\u4f46\u662f\u5b83\u4e5f\u6709\u4e00\u4e9b\u7f3a\u70b9\uff0c\u9700\u8981\u6ce8\u610f\u3002<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"
sscanf\u51fd\u6570\u662f\u4e00\u79cdC\u8bed\u8a00\u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u4ece\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u51fa\u6307\u5b9a\u7684\u6570\u636e\u3002\u5b83\u4e0escanf\u51fd\u6570\u7684\u529f\u80fd\u7c7b\u4f3c\uff0c\u4f46\u662f\u5b83\u66f4\u52a0\u7075\u6d3b\uff0c\u53ef\u4ee5\u5904\u7406\u66f4\u591a\u590d\u6742\u7684\u6570\u636e\u7c7b\u578b\u3002\u672c\u6587\u5c06\u4ecb\u7ecdsscanf\u51fd<\/p>\n","protected":false},"author":1,"featured_media":4132,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[36],"tags":[212],"class_list":["post-40256","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-ctx"],"_links":{"self":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts\/40256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/comments?post=40256"}],"version-history":[{"count":0,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts\/40256\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/media\/4132"}],"wp:attachment":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/media?parent=40256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/categories?post=40256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/tags?post=40256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}