函数声明
int sprintf(char *string, char *format [,argument,...]);
参数列表
-
string-- 这是指向一个字符数组的指针,该数组存储了 C 字符串。
-
format-- 这是字符串,包含了要被写入到字符串 str 的文本。它可以包含嵌入的 format 标签,format 标签可被随后的附加参数中指定的值替换,并按需求进行格式化。format 标签属性是%[flags][width][.precision][length]specifier
-
[argument]...:根据不同的 format 字符串,函数可能需要一系列的附加参数,每个参数包含了一个要被插入的值,替换了 format 参数中指定的每个 % 标签。参数的个数应与 % 标签的个数相同。
-
功能
把格式化的数据写入某个字符串缓冲区,根据自己使用,可以实现字符串复制,和字符串拼接,以及字符型数据与其他类型数据拼接,最后以字符串形式存入string。
while(1) { memset(abs_find_path,0,PATH_LEN); struct dirent * eq = readdir(dp); if(eq == (struct dirent *)NULL) { //perror("读取完成!"); break; } if(eq->d_name[0] == '.') continue; //忽略.和.. if(obj_dir_path[strlen(obj_dir_path)-1] == '/') sprintf(abs_find_path,"%s%s",obj_dir_path,eq->d_name); else sprintf(abs_find_path,"%s/%s",obj_dir_path,eq->d_name); if(eq->d_type == DT_REG) { if(strcmp(eq->d_name,obj_file_path) == 0) { printf("hit obj file: %s\n",abs_find_path); } } if(eq->d_type == DT_DIR) { Dir_Search(abs_find_path, obj_file_path); } }