//来源:天勤计算机考研复试上机指导
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
//从字符串中取出数字
//sscanf以一个已知的字符串作为输入源
printf("sscanf用法示例:\n");
char time[] = "9:25:12";
int hh, mm, ss;
sscanf(time, "%d:%d:%d", &hh, &mm, &ss);
printf("%d %d %d\n\n", hh, mm, ss);
//sprintf将某些数据按某种格式写入一个字符串
printf("sprintf用法示例:\n");
char time1[10];
sprintf(time1, "%d:%d:%d", 9, 25, 12);
printf("%s\n\n", time1);
//strstr(str1, str2)在str1中查找str2是否存在,返回str2首次出现位置,不存在则返回NULL
printf("strstr用法示例:\n");
char str1[] = "hello world";
char str2[] = "llo";
char *find = strstr(str1, str2);
if(find != NULL)
printf("%s\n\n", find);
cout << endl;
return 0;
}
c库函数
最新推荐文章于 2024-03-05 23:26:21 发布