问一下,如何用C语言提取Printf里的数据?

来源:百度知道 编辑:UC知道 时间:2024/06/06 16:55:07
比如printf( "%.19s %s\n", asctime( newtime ), am_pm );
我要提取里面的时间数据,然后在printf("%s\n",recvBuf);这里输出,应该用什么函数呢?

要获取输出的内容 用 sprintf

char buffer[100];

printf("%.19s %s\n", asctime( newtime ), am_pm );
sprintf(buffer, "%.19s %s\n", asctime( newtime ), am_pm );

printf 是将内容输出到屏幕
sprintf 是将内容输出到字符串

然后从 buffer 里提取数据就可以了