sscanf与sprintf

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_43912065/article/details/95459186

sscanf可以理解为string+scanf;sprintf可以理解为string+printf。
(均在stdio.h头文件下)
假设定义了一个char数组str[100],可写为
sscanf(str,"%d",&n);
sprintf(str,"%d\n",n);
当然,它的应用格式不止一种,还有一种为
sscanf(str,"%d:%1f,%s",&n,&db,str2);
ssprintf(str,"%d:%2f,%s",n,db,str2);
要记住的是,sscanf与spintf一般不同时存在

猜你喜欢

转载自blog.csdn.net/weixin_43912065/article/details/95459186