Chinaunix首页 | 论坛 | 博客
  • 博客访问: 294304
  • 博文数量: 70
  • 博客积分: 1990
  • 博客等级: 上尉
  • 技术积分: 686
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-02 08:52
文章分类

全部博文(70)

文章存档

2015年(2)

2014年(9)

2013年(2)

2012年(20)

2011年(1)

2010年(36)

分类: C/C++

2010-12-02 17:09:39

说明:函数功能是将一个字符串的内容按格式输入,遇到第一个空白字符会结束,可用于字符转数字,类似于atoi。
源码: 
/* SSCANF.C: This program uses sscanf to read data items
 * from a string named tokenstring, then displays them.
 */
#include
void main( void )
{
   char  tokenstring[] = "15 12 14...";
   char  s[81];
   char  c;
   int   i;
   float fp;
   /* Input various data from tokenstring: */
   sscanf( tokenstring, "%s", s );
   sscanf( tokenstring, "%c", &c );
   sscanf( tokenstring, "%d", &i );
   sscanf( tokenstring, "%f", &fp );
   /* Output the data read */
   printf( "String    = %s\n", s );
   printf( "Character = %c\n", c );
   printf( "Integer:  = %d\n", i );
   printf( "Real:     = %f\n", fp );
}
Output
String    = 15
Character = 1
Integer:  = 15
Real:     = 15.000000
阅读(2020) | 评论(1) | 转发(0) |
0

上一篇:linux编程小结

下一篇:打印机安装

给主人留下些什么吧!~~

chinaunix网友2010-12-03 15:56:00

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com