①sscanf()
语法:
#include <stdio.h>int sscanf( const char *buffer, const char *format, ... ); |
函数sscanf()和scanf()类似, 只是输入从buffer(缓冲区)中读取.
/* sscanf example */
#include <stdio.h>int main ()
{char sentence []="Rudolph is 12 years old";char str [20];int i;sscanf (sentence,"%s %*s %d",str,&i);printf ("%s -> %d\n",str,i);return 0;
}
/*输出:
Rudolph -> 12
*/
②
语法:
#include <stdio.h>int sprintf( char *buffer, const char *format, ... ); |
sprintf()函数和printf()类似, 只是把输出发送到buffer(缓冲区)中.
返回值:
成功后,将返回写入的字符总数。
失败时,将返回负数。
/* sprintf example */
#include <stdio.h>int main ()
{char buffer [50];int n, a=5, b=3;n=sprintf (buffer, "%d plus %d is %d", a, b, a+b);printf ("[%s] is a string %d chars long\n",buffer,n);return 0;
}
/*输出
[5 plus 3 is 8] is a string 13 chars long
*/